Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Syntax for a list of comparable objects

I'm writing a method that takes as its only parameter a list of comparable objects and doesn't return anything. I am uncertain as to the syntax that it should have:

public static void methodName(List<Comparable<Object>> list) {
    // Do some stuff
}

I think this is wrong because of the <Object> as a type for Comparable, which would mean the list can take an Integer and a Boolean as objects, but I don't want that. I want the list to take only one type, but that type has to implement the Comparable interface. How do I achieve that?

like image 242
Sotirios Delimanolis Avatar asked May 26 '12 03:05

Sotirios Delimanolis


1 Answers

Maybe make it generic?

public static <E extends Comparable<E>> void methodName(List<E> list) ...
like image 98
Jordão Avatar answered Sep 21 '22 00:09

Jordão