Does java support inheritance inside the diamond operator? [duplicate]

This question already has an answer here:

Generics : List is same as List?

3 answers

In Java Generics are invariant?

3 answers

I was trying to do the convert an ArrayList of Users to an ArrayList of Comparable, the class Users implements Comparable, but this seems not possible. Here is the code I wrote in order to test this functionality:

public static void main(String[] args) {

ArrayList users = new ArrayList();

users.add(new User("Tom", "Jefferson",2));

users.add(new User("White", "Walt", 29));



//return the greatest item in the array list

public static Comparable getGreatest(ArrayList arrayList){

Comparable greatest = arrayList.get(0);

for(Comparable c : arrayList){

if (c.compareTo(greatest)...

Read More »

By: StackOverFlow - Thursday, 8 November

Related Posts