casting and ClassCastException

Oskar Liljeblad osk@hem.passagen.se
Tue Jul 25 15:27:00 GMT 2000


In the libgcj implementation of java.lang.* classes you see
methods like this one:

   public int compareTo(Object o) throws ClassCastException
   {
    if (o instanceof Byte)
      return this.value - ((Byte) o).value;
    else
      throw new ClassCastException();
    }

My question is: why throw ClassCastException when that is automaticly
done if you cast right away, like this:

    return this.value - ((Byte) o).value;

Oskar Liljeblad (osk@hem.passagen.se)


More information about the Java mailing list