Source: http://user.qzone.qq.com/31584 (QQ space)
Http:// B .qzone.qq.com/cgi-bin/blognew/blog_output_data? Uin = 31584 & blogid = 1270205768 & styledm = Hangzhou & imtpd = qzs.qq.com & BDM = B .qzone.qq.com & mode = 2 & numperpage = 15 & blogseed = 0.7275722332481711 & property = Gore & timestamp = 1273108498 (actual address)
Testref. Java
Import Java. Lang. Reflect. method;
Import Java. Lang. Reflect. invocationtargetexception;
/**
* Created by intellij idea.
* File: testref. Java
* User: String
* Date: 14:48:44
*/
Public Class Testref {
Public Static Void Main (string ARGs []) Throws Nosuchmethodexception, illegalaccessexception, invocationtargetexception {
Foo = New Foo ( " This Foo object! " );
Class clazz = Foo. getclass ();
Method M1 = Clazz. getdeclaredmethod ( " Outinfo " );
Method m2 = Clazz. getdeclaredmethod ( " Setmsg " , String. Class );
Method m3 = Clazz. getdeclaredmethod ( " Getmsg " );
M1.invoke (FOO );
M2.invoke (Foo, " Reset MSG information! " );
String msg = (String) m3.invoke (FOO );
System. Out. println (MSG );
}
}
Class Foo {
Private String MSG;
Public Foo (string MSG ){
This . Msg = MSG;
}
Public Void Setmsg (string MSG ){
This . Msg = MSG;
}
Public String getmsg (){
Return MSG;
}
Public Void Outinfo (){
System. Out. println ( " This is a test class for testing Java reflection. " );
}
}
Console output result:
This is a test class for testing Java reflection.
Reset MSG information!
Process finished with exit code0