I know how to implement the Comparable interface... I have just one question.
public class RealNumber implements Comparable {
public int compareTo(Object obj) {
// What do you do when obj is not an instance of RealNumber?
}
}
In the compareTo
method, are you supposed to handle the case where obj is not an instance of RealNumber? Should you throw an Exception in this case?
Or should you just assume the class invoking your compareTo method only does it for other RealNumber
instances?