Java syntax for a list of comparable objects

I am writing a method that takes as a single parameter a list of comparable objects and returns nothing. I am not sure of the syntax that should have:

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

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

+6
source share
1 answer

Maybe this is common?

 public static <E extends Comparable<E>> void methodName(List<E> list) ... 
+10
source

Source: https://habr.com/ru/post/916721/


All Articles