[JAVA] Reflect 練習
查詢JVM的class支援哪些Methods的方法
import java.lang.reflect.Method;
public class ClassCase {
public void testClass(String name){
try{
Method[] ms = Class.forName(name).getDeclaredMethods();
for(Method m:ms){
System.out.println("Method:... " +m.getName());
}
}
catch (Exception ex){
ex.printStackTrace();
}
}
public static void main(String[] args){
//(Class.forName("ClassCase").newInstance()).testClass();
if (args.length == 1){
new ClassCase().testClass(args[0]);
}else
{
System.out.println("Usage: JVM -jar ClassCase.jar CLASS_NAME");
System.exit(0);
}
}
}
Comments
Post a Comment