Java 泛型和反射

反射常用的泛型类

  • Class
  • Constructor
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test {
	public static void main(String[] args) throws Exception {
		
		Class<Person> personClass = Person.class;
		Constructor<Person> constructor = personClass.getConstructor();
		Person newInstance = constructor.newInstance();
		
		Class personClass1 = Person.class;
		Constructor constructor2 = personClass1.getConstructor();
		Object newInstance2 = constructor2.newInstance();
	}
}

你可能感兴趣的:(Java)