import java.lang.reflect.*;
class RealObject {
public void doSomething() { System.out.println("doSomething"); }
public void somethingElse() {
System.out.println("somethingElse" );
}
}
public class P340_21 {
public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
RealObject r = new RealObject();
Method[] ms = r.getClass().getDeclaredMethods();
for(Method m : ms)
{
m.invoke(r, null);
System.out.println(m.getClass().getName());
}
}
}
/*输出是:
doSomething
java.lang.reflect.Method
somethingElse
java.lang.reflect.Method
*/
//为什么不是输出方法名?