目录
抽象类
public abstract Commonder<T extends Person>{
protected final T person;
public Commonder(T person){
this.person=person;
}
}
public class UserCommonder<User>{
public UserCommonder(User person){
super(person);
}
}
基于Class参数创建新对象
public static <T> T newInstance(Class<T> tClass,Object...objects) {
try {
return tClass.getConstructor().newInstance(objects);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}