Search code examples
javagenericscomparable

Usage of Comparable Interface with generic static method in Java


How to use Comparable interface with generic static method?

Suppose lets say I have:

**public static <T extends Comparable<T>>int larger(T[] array,T element)**

Why should I extend an Interface with T here instead of using implements?

Please Help me out.Thanks.


Solution

  • According to Java generics, you should use extends even to interfaces, there's no such thing as impelements in bounded types.