Writing some classes for a Framework extension, and I have the following code:
public class TimeImpl implements Time, Comparable<TimeImpl>, Serializable
{
...
public int compareTo(TimeImpl other)
{
if (other == null)
throw new ClassCastException("null");
return Long.valueOf(toSeconds()).compareTo(other.toSeconds());
}
}
Pretty straightforward implementation, if you ask me. My question is: as far as I can tell, the javadocs for the Comparable interface say nothing regarding null arguments. Should I bother checking for it? Should I change the type of exception thrown, should I return some other value in that case? How are other people out there handling this?