Relates :
|
|
Relates :
|
|
Relates :
|
java.lang.Class.cast(Object) (JDK 5 or 6) has throw new ClassCastException(); with no detail message. Regular CCEs seem to give at least the class name of the actual object as a detail message, on the assumption that this is information the programmer does not know and may need in order to debug it. In JDK 6 it seems the expected class name is given too. Class.cast(...) should give at least as much information. The expected type is in fact more important than for a direct cast, since for this method call the identity of the Class object may not be statically known. So would suggest e.g. throw new ClassCastException(obj.getClass().getName() + " cannot be cast to " + getName());
|