Java??÷?????÷???
???????????? ???????[ 2013/8/7 10:56:24 ] ????????
????????sinablogд???????????÷?????????????class????????????????class???????ε???????????????????????????????method???invoke???????????????????£????jdk??api????????????????
package methodinvoke;
import java.lang.reflect.Method;
public class Test {
public String function () {
return "????function";
}
@SuppressWarnings("unchecked")
public static void main(String[] args) {
try {
//????forname??????????????class???????????
Class c = Class.forName("methodinvoke.Test");
//?????????????????
Test t = (Test) c.newInstance();
System.out.println("------------------------????");
//?????????name
System.out.println("//class.getname");
System.out.println(c.getName());
//???????????????????name
System.out.println("//obj.tostring");
System.out.println(t);
System.out.println("------------------------????");
//???????????????class???????name
System.out.println("//method.class.getname");
System.out.println(c.getMethod("function"?? null).getClass().getName());
System.out.println("//method.getname");
//????????????name
System.out.println(c.getMethod("function"?? null).getName());
System.out.println("//???÷???");
//????t???????????????????
System.out.println(c.getMethod("function"?? null).invoke(t?? null));
System.out.println("------------------------????????????");
Method[] methods = c.getMethods();
//????????????????е???????
for (int i = 0;i < methods.length;i++) {
//????????class???????name
System.out.println(methods[i].getClass().getName());
//????????name
System.out.println(methods[i].getName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11