0){greatest = c;}}return greatest;}Of curse the User class implements the interface Comparable and has the method compareTo.class User implements..." />

Does java support inheritance inside the diamond operator?

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));

System.out.println(getGreatest(users));

}

//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) > 0){

greatest = c;

}

}

return greatest;

}

Of curse the User class implements the interface Comparable and has the method compareTo.

class User implements...

Read More »

By: StackOverFlow - Thursday, 8 November

Related Posts