Multiple instances of Comparable Interface / compareTo in a class
in
Programming Questions
•
1 year ago
Hello all,
I've used an instance of the Comparable interface in my class to reorder the object by id and I'm wondering if it's possible to resort the object by other criteria (such as date) by using two instances of the interface.
My apologies ahead of time if this is a bit of a JAVA newb question. I'm still getting the hang of diving deeper into the language from Processing. Example of what I'm doing below (I believe Comparable's been discussed before in this forum but not asked about like this):
public class Joe implements Comparable {
...
int compareTo(Object o)
{
Joe other=(Joe)o;
if (other.id>id)
return -1;
if (other.id==id)
return 0;
else
return 1;
}
...
I've used an instance of the Comparable interface in my class to reorder the object by id and I'm wondering if it's possible to resort the object by other criteria (such as date) by using two instances of the interface.
My apologies ahead of time if this is a bit of a JAVA newb question. I'm still getting the hang of diving deeper into the language from Processing. Example of what I'm doing below (I believe Comparable's been discussed before in this forum but not asked about like this):
public class Joe implements Comparable {
...
int compareTo(Object o)
{
Joe other=(Joe)o;
if (other.id>id)
return -1;
if (other.id==id)
return 0;
else
return 1;
}
...
1