3

I read the question about Sort a Map<Key, Value> by values (Java). The second answer mentioned

public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map )

I was confused with the part

<K, V extends Comparable<? super V>>

Can I explain it as "V has to be subclass of any class which implements Comparable interface" ? Or how should I explain it into words?

Does it equivalent to

public static <K, V extends Comparable<V>>

?

Thanks.

Community
  • 1
  • 1
user1552891
  • 527
  • 5
  • 4
  • 3
    More like "V has to be *comparable* with itself or any of its superclasses". This is so you can have `class Animal implements Comparable`, and `class Dog extends Animal`, and still sort a collection of `Dog`s. In your latter signature, this wouldn't be possible. – millimoose Oct 09 '13 at 00:51
  • Thanks very much. > means the type T must implement Comparable of T or one of its super classes. > means T must implement Comparable of T. – user1552891 Oct 09 '13 at 03:45

0 Answers0