如题所述
Reflection(反射) 是Java被视为动态(或准动态)语言的一个关键性质。这个机制允许程序在运行时透过Reflection APIs取得任何一个已知名称的class的内部信息,包括其modifiers(诸如public, static 等等)、superclass(例如Object)、实现interfaces(例如Serializable),也包括fields和methods的所有信息,并可于运行时改变fields内容或调用methods。
例如:
import java.lang.reflect.Method;
public class DumpMethods
{
public static void main(String[] args) throws Exception
{
Class<?> classType = Class.forName(args[0]);
Method[] methods = classType.getDeclaredMethods();
for(Method method : methods)
{
System.out.println(method);
}
}
}
例如:
import java.lang.reflect.Method;
public class DumpMethods
{
public static void main(String[] args) throws Exception
{
Class<?> classType = Class.forName(args[0]);
Method[] methods = classType.getDeclaredMethods();
for(Method method : methods)
{
System.out.println(method);
}
}
}
温馨提示:答案为网友推荐,仅供参考