I have a little problem, i hope you could help me solve it.
I have a class called Entity which has several attributes, two of those attributes are the id and the utility:
public class Entity implements Comparable <Entity> {
int id;
int utility;
}
Then, i have several Entity objects inside an ArrayList, like this:
ArrayList<Entity> sorted_entities = new ArrayList<Entity>
//added entities
Now, i want to sort the list basing on UTILITY entities. I tried several soluctions like this one which i read here, using a custom comparator:
Collections.sort(sorted_entities, new Comparator<Entity>() {
public int compare(Entity a, Entity b) {
return a.utility.compareTo(b.utility);
}
});
But on this line:
return a.utility.compareTo(b.utility);
I met the following error: int cannot be dereferenced and i have no idea how fix it. Can you guys help me solve this problem or give another solution? Thx.