mercredi 4 mars 2015

how to have a reference to child generic type from a parent generic type?



here is the scenario



class MyClass1{

}

class MyClass2 extends MyClass1{

}

class Parent<T>{
List<T> list;
}


class Child extends Parent<MyClass2>{
}


this doesn't compile



Parent<MyClass1> p = new Child();


this does



Parent<MyClass2> p = new Child();


why?


is there a way to refer via parent type?




Aucun commentaire:

Enregistrer un commentaire