roy
roy

Reputation: 371

Generic Methods Java

Is there any difference between these 2 generic methods?

  1. public static <E> void fill(ArrayList<? extends Comparable<? super E>> a)

  2. public static <E extends Comparable<? super E>> void fill2(ArrayList<E> a)

Upvotes: 4

Views: 180

Answers (1)

Rafael Winterhalter
Rafael Winterhalter

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

Related Questions