title: Java's Comparable Interface: Handling null arguments to compareTo()
body: <p>Writing some classes for a Framework extension, and I have the following code:</p>
  
  <pre><code>public class TimeImpl implements Time, Comparable&lt;TimeImpl&gt;, Serializable
  {
  ...
      public int compareTo(TimeImpl other)
      {
          if (other == null)
              throw new ClassCastException("null");
          return Long.valueOf(toSeconds()).compareTo(other.toSeconds());
      }
  }
  </code></pre>
  
  <p>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?</p>