I have those two classes as example :
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);
}
}
and
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();
}
}
- Instantiation of T failed: "Cannot instantiate the type T"
- Instantiation via getInstance static method failed: "Type mismatch: cannot convert from AClass to T"
- Why not? I don't understand why you cannot do this.
- Why cannot convert AClass to T since T is subclass of AClass?