List of usage examples for java.lang Class getDeclaredMethods
@CallerSensitive public Method[] getDeclaredMethods() throws SecurityException
From source file:Main.java
public static void main(String[] argv) throws Exception { Class cls = java.lang.String.class; Method[] methods = cls.getDeclaredMethods(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class computerClass = MyClass.class; Method[] methods = computerClass.getDeclaredMethods(); MyClass computer = new MyClass(); for (Method method : methods) { Object result = method.invoke(computer, new Object[0]); System.out.println(method.getName() + ": " + result); }//from w w w. j ava2s. c o m }
From source file:Main.java
public static void main(String... args) { try {//from w ww. ja va2 s . c o m Class<?> c = Class.forName("Main"); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { Annotation[][] types = m.getParameterAnnotations(); } } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static void main(String... args) { try {/* w w w . jav a 2 s . c o m*/ Class<?> c = Class.forName("Main"); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { Type gpType = m.getGenericReturnType(); System.out.println(gpType); } } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static void main(String... args) { try {//ww w . ja va 2s. c o m Class<?> c = Class.forName("Main"); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { TypeVariable[] types = m.getTypeParameters(); for (TypeVariable t : types) { System.out.println(t); } } } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static void main(String... args) { try {// w w w. j a v a 2s .com Class<?> c = Class.forName("Main"); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { Class<?>[] pType = m.getParameterTypes(); Type[] gpType = m.getGenericParameterTypes(); for (int i = 0; i < pType.length; i++) { out.format(fmt, "ParameterType", pType[i]); out.format(fmt, "GenericParameterType", gpType[i]); } } } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { MyClass cls = new MyClass(); Class c = cls.getClass(); // returns the array of Method objects Method[] m = c.getDeclaredMethods(); for (int i = 0; i < m.length; i++) { System.out.println("method = " + m[i].toString()); }//ww w.j a v a 2 s . c om }
From source file:MethodSpy.java
public static void main(String... args) { try {//from w w w . j a v a2 s . co m Class<?> c = Class.forName(args[0]); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { if (!m.getName().equals(args[1])) { continue; } out.format("%s%n", m.toGenericString()); out.format(fmt, "ReturnType", m.getReturnType()); out.format(fmt, "GenericReturnType", m.getGenericReturnType()); } // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:ReflectionDemo2.java
public static void main(String args[]) { try {/*from w w w . jav a 2s . c o m*/ A a = new A(); Class c = a.getClass(); System.out.println("Public Methods:"); Method methods[] = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { int modifiers = methods[i].getModifiers(); if (Modifier.isPublic(modifiers)) { System.out.println(" " + methods[i].getName()); } } } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:MainClass.java
public static void main(String args[]) { try {//from w w w.j av a 2 s. co m MyClass a = new MyClass(); Class c = a.getClass(); System.out.println("Public Methods:"); Method methods[] = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { int modifiers = methods[i].getModifiers(); if (Modifier.isPublic(modifiers)) { System.out.println(" " + methods[i].getName()); } } } catch (Exception e) { System.out.println("Exception: " + e); } }