Tuesday, January 31, 2012

Return no wildcard

From Effective Java, 2nd edition:

Do not use wildcard types as return types.

E.g.,
public static <E> Set<E> union(Set<E> s1, Set<E> s2)
should be re-written
public static <E> Set<E> union(Set<? extends E> s1, Set<? extends E> s2)