[英]Instantiation of a generic type?
我以这两个类为例:
public class AClass {
public int i;
public static int static_i;
public AClass(int i) {
}
public void aMethod() {}
public static void aStaticMethod() {}
public static AClass getInstance(int i) {
return new AClass(i);
}
}
和
public class AnOtherClass<T extends AClass> {
T aMember;
public void method() {
// Instanciation of T failed
aMember = new T(0);
// Instanciation via getInstance static method failed
aMember = T.getInstance(0);
// OK
T.aStaticMethod();
// OK
aMember.aMethod();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.