Java wildcards and generics ? super T and ? extends T
问题 when dealing with wildcards such as setting/adding a generic item to a certain container is it suggested to use something like this? void add(List<? super T> someList,someitem){ someList.add(someItem); } and when retrieving an item it is suggested to use something like this <T> void f1(List<? extends T> obj, T item) { obj.add(item); } What is the principle behind this? and when will I know if I should use this ? 回答1: you should have a look at the explanation of PECS principle What is PECS