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 cats. 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 dogs.



so doubt is: there accessible proceed category once, following illusory animals? impetus should solve sincerely above mentioned problem.



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members