Class.getDeclaredMethod(String name, Class <?>... parameterTypes) has the following syntax.
public Method getDeclaredMethod(String name, Class <?>... parameterTypes) throws NoSuchMethodException , SecurityException
In the following code shows how to use Class.getDeclaredMethod(String name, Class <?>... parameterTypes) method.
/*from w ww . j a v a 2 s .c o m*/ import java.lang.reflect.Method; public class Main { public static void main(String[] args) { Main cls = new Main(); Class c = cls.getClass(); try { Method m = c.getDeclaredMethod("show", null); System.out.println("method = " + m.toString()); // method Integer Class[] cArg = new Class[1]; cArg[0] = Integer.class; Method lMethod = c.getDeclaredMethod("showInteger", cArg); System.out.println("method = " + lMethod.toString()); } catch(NoSuchMethodException e) { System.out.println(e.toString()); } } } class MyClass{ private Integer show() { return 1; } public void showInteger(Integer i) { this.i = i; } public int i = 12345; }
The code above generates the following result.