Java syntax for a list of comparable objects
•
Java
I'm writing a method that takes unique parameters as a list of comparable objects and returns nothing I'm not sure what syntax it should have:
public static void methodName(List<Comparable<Object>> list) { // Do some stuff }
I think this is wrong because < Object > is a comparable type, which means that lists can take integers and Boolean values as objects, but I don't want this I want the list to take only one type, but the type must implement the comparable interface How can I achieve this goal?
Solution
Maybe make it universal?
public static <E extends Comparable<E>> void methodName(List<E> list) ...
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码