I have a class called Target with a parameter called double currentAzimuth that is returned by .getCurrentAzimuth(). In another class, I have an ArrayList full of these Target objects. I am needing to sort the List by each objects currentAzimuth.
This is what I am trying in my Target class:
static class AzimuthComparator implements Comparator
{
public double compare(Object o1, Object o2)
{
Target t1 = (Target)o1;
Target t2 = (Target)o2;
return t1.getCurrentAzimuth() - t2.getCurrentAzimuth();
}
}
And this in my other class:
Collections.sort(targetArrayList, new AzimuthComparator());
Eclipse is giving me this error: The return type is incompatible with Comparator.compare(Object, Object)
I looked up the Comparator in the API (http://java.sun.com/j2se/1.5.0/docs/api/java/util/Comparator.html#compare%28T,%20T%29) and sure enough, it only returns an int.
Am I going about attempting this correctly, and if not, what should I be trying to do. Thanks.