T
Torkel Franzen
I'm looking at that showcase example of generification (from
java.util.Collections):
public static <T extends Object & Comparable<? super T>> T
min(Collection<? extends T> coll)
The reasons for the restriction on the parameter T are clear. But
given that restriction, why the wildcard in the type of coll?
Suppose we define a method
public static <T extends Object & Comparable<? super T>> T
min1(Collection<T> coll)
If T is a subtype of Comparable<S> and a subtype of S, then given
any subtype U of T, U is a subtype of Comparable<S> and a
subtype of S. So what calls go through for min but not for min1?
java.util.Collections):
public static <T extends Object & Comparable<? super T>> T
min(Collection<? extends T> coll)
The reasons for the restriction on the parameter T are clear. But
given that restriction, why the wildcard in the type of coll?
Suppose we define a method
public static <T extends Object & Comparable<? super T>> T
min1(Collection<T> coll)
If T is a subtype of Comparable<S> and a subtype of S, then given
any subtype U of T, U is a subtype of Comparable<S> and a
subtype of S. So what calls go through for min but not for min1?