How to set constraints on generic types in Java?

Read also the discussion here: Generics and sorting in Java

Short answer, the best you can get is:

class ListObject<T extends Comparable<? super T>> {
    ...
}

But there is also reason to just use:

class ListObject<T extends Comparable> {
    ...
}

Leave a Comment