Reputation: 371
Is there any difference between these 2 generic methods?
public static <E> void fill(ArrayList<? extends Comparable<? super E>> a)
public static <E extends Comparable<? super E>> void fill2(ArrayList<E> a)
Upvotes: 4
Views: 180
Reputation: 44042
Yes, the binding of E
is different. Given some
class Foo implements Comparable<Foo>
and some
class Bar implements Comparable<Foo> // Not Bar!
Foo
would be a legal argument to both fill
and fill2
as the second method requires E = Foo
to both extend Comparable
and to have this Comparable
implementation to be of E = Foo
. This cannot be fulfilled by Bar
.
Upvotes: 5