It might be a noob question but I am learning java and I came across an interface which had its definition like :
public interface MyClass <T extends Comparable<T>>
Can someone please explain what does it mean? I mean what kind of interface is created.
It means that the generic type argument must implement the
Comparableinterface.When specifying
<T extends Comparable<T>>you can use e.g. Collections.sort in this interface on typeT. Withoutextendsyou can not guarantee thatTis comparable.Numbers and String are e.g. comparable and implement the
Comparableinterface.