Generics - Legal alternative for (elements instanceof List<? extends Comparable>)

Viewed 3365

I have this method which unique parameter (List elements) sets elements to a ListModel, but I need to make a validation to see if the generic type implements comparable and since such thing like:

if (elements instanceof List<? extends Comparable>)

is illegal, I don't know how to do the proper validation.

Update

I already have done this validation using:

(elements.size() > 0 && elements.get(0) instanceof Comparable)

but I want to know if is there a cleaner solution for that, using for example reflection?

Thanks in advance.

4 Answers
Related