Two reasons:
To avoid unnecessary broadcasts:
You should use option T for such cases:
public <T extends Set> T firstOf(List<T> l) { return l.get(0); }
C this will become the following:
public Set firstOf2(List<? extends Set> l) { return l.get(0); }
... which does not give the same amount of information to the caller of the firstOf method. The first version allows the caller to:
SubSet first = firstOf(listOfSubSet);
and in the second version, you are forced to use a cast to compile it:
SubSet first = (SubSet)firstOf(listOfSubSet);
To apply the appropriate argument types:
public <T extends Set> boolean compareSets(List<T> a, List<T> b) { boolean same = true; for(T at : a) { for (T bt: b) { same &= at.equals(bt); } } return same; }
There is no direct equivalent for this using ? instead of T . Note that due to the separate sending of Java in the above version, the compiler will call the at equals(T) method, which can be very different from the at equals(Set) or equals(Object) method.
blubb
source share