I am trying to ignore exactly what it is your doing, but however offer
the following options.
If you are expecting an Integer object, then why not make the
parameter an integer?
public int compareTo(Integer t){
int temp = t.intValue();
return temp;
}
otherwise, check for the instance so you won't get a
ClassCastException. Here's a couple of examples (I prefere the first
one):
public int compareTo(Object t){
int temp = DEFAULT_VALUE;
if (t instanceof Integer) {
temp = ((Integer)t).intValue();
}
return temp;
}
public int compareTo(Object t){
int temp = -1;
try {
temp = ((Integer)t).intValue();
} catch (Exception e) {
// ignore
temp = DEFAULT_VALUE;
}
return temp;
}