标签:ref dcl reflect line 运行 pretty test 隐藏 运行时
public class TestClass {public static void main(String[] args) throws ClassNotFoundException {// 通过运行时类本身的.class静态属性(隐藏的)来获取Class<Person> clazz1 = Person.class;System.out.println(clazz1);// class com.cdf.reflection.Person// 通过运行时类对象的 getClass() 方法(隐藏的)来获取Person p = new Person();Class<Person> clazz2 = (Class<Person>) p.getClass();System.out.println(clazz2);// class com.cdf.reflection.Person// 通过 Class 类的静态方法传入类的全名来获取Class clazz3 = Class.forName("com.cdf.reflection.Person");System.out.println(clazz3);// class com.cdf.reflection.Person// 4.通过类的加载器ClassLoader classLoader = new TestClass().getClass().getClassLoader();Class clazz4 = classLoader.loadClass("com.cdf.reflection.Person");System.out.println(clazz4);// class com.cdf.reflection.Person}}
标签:ref dcl reflect line 运行 pretty test 隐藏 运行时
原文地址:http://www.cnblogs.com/chendifan/p/6569126.html