1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package com.sympa.lesson01;
import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method;
public class ReflectionTest {
public static void main(String[] args) throws ClassNotFoundException {
Class clazz = Person.class;
Person person = new Person(); Class clazz1 = person.getClass();
Class clazz2 = Class.forName("com.sympa.lesson01.Person");
System.out.println(clazz == clazz1); System.out.println(clazz == clazz2);
ClassLoader classLoader = ReflectionTest.class.getClassLoader(); Class clazz3 = classLoader.loadClass("com.sympa.lesson01.Person");
} }
|