类:
public class Phone {
public boolean getInfo(int id){
if(id == 1){
System.out.println("good");
}else{
System.out.println("not good!");
}
return true;
}
}
调用:
public class T {
public static void main(String[] args) throws Exception{
T t = new T();
Phone p = new Phone();
Class c = p.getClass();
Method[] ms = c.getMethods();
for(int i=0;i<ms.length;i++){
Method m = ms[i];
System.out.println(m.getName());
if(m.getName().equals("getInfo")){
boolean va = (Boolean)m.invoke(p, new Object[]{1});
System.out.println(va);
break;
}
}
}
}
结果:
getInfo
good
true