java 泛型 编译报错
代码如下:
package com.nettyClazzTest;
public class App {
public static void main(String[] args) {
GenericTest nettyTest=new GenericTest();
Person p= nettyTest.add(Person.class);
}
}
class GenericTest<T>{
public T add(Class<T> calzz){
try {
return calzz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
};
}
class Person{}
这一行编译报错
Person p= nettyTest.add(Person.class);
什么原因啊? 大佬们 help