how understanding "super" generics java?
take following generics example
import java.util.list;
import java.util.arraylist;
public category genericstest {
private list<animal> mylist;
open stationary vacant main(string args[]) {
new genericstest(new arraylist<animal>()).add(new dog());
}
open genericstest(list<animal> list) {
mylist = list;
}
open vacant add(animal a) {
mylist.add(a);
}
open interface animal {}
open stationary category dog implements animal {}
open stationary category cat implements animal {}
}
it works fine. nonetheless know, can't make with
new genericstest(new arraylist<dog>());
because, know, add(animal) illusory supplement cat
s. suggested proceed clarify problem, i.e. wildcarding does work either, because, yes, change each list<animal>
list<? extends animal>
nonetheless same problem: emanate genericstest
list<cat>
following supplement dog
s.
so doubt is: there accessible proceed category once, following illusory animals
? impetus should solve sincerely above mentioned problem.
Comments
Post a Comment