Common Java Methods

Is there a difference between these two common methods?

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

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

+4
source share
1 answer

Yes, the binding Eis different. Given some

class Foo implements Comparable<Foo>

and some

class Bar implements Comparable<Foo> // Not Bar!

Foowill be a legal argument both for filland for fill2, since the second method is required E = Foofor expansion Comparableand for implementation Comparable E = Foo. This cannot be done Bar.

+5
source

All Articles