1 public class Demo { 2 3 /** 4 * 反射:加载类,获得类的字节码 5 * @param args 6 * @throws ClassNotFoundException 7 */ 8 public static void main(String[] args) throws ClassNotFoundException { 9 10 //1 11 Class clazz = Class.forName("Person"); 12 13 //2 14 Class clazz1 = new Person().getClass(); 15 16 //3 17 Class clazz2 = Person.class; 18 19 } 20 21 }
时间: 2024-12-26 19:23:38