Java Reflection
Purpose: use the Instances of the class java.lang.Class to represent classes and interfaces in a running Java application.1. create Object:
A a = (A)Class.forName("A").newInstance(); //If A isn't a correct Class Name, it's a Runtime-Exception "ClassForName", comparing to the Compile-Exception from "new A()"
2. get Attributes/Methods information at Runtime:
Class c = Class.forName(args[0]);
Method m[] = c.getDeclaredMethods();
posted on 2007-06-12 13:14 Xiaobo Sun 閱讀(222) 評論(0) 編輯 收藏 所屬分類: Java