Java Casting query Exception and error -
When do we get an incompatible type compilation error in Java and when do we get class class exception?
The API specification clearly states:
For that code, the object is attempting to put an object in a subclass in which this is not an example.
ClassCastException is generated at runtime because the compiler believes that the cast can be valid.
Example:
// The bottom line will be compiled but the class class upstream runtime integer will be raised on the I = (integer) new object ();
Incompatible type error can be easily solved by compiling it at compiled time. It only appears that the category for which you are trying to insert a specific object falls into the same hierarchy.
Example:
string str = "abc"; & Lt; Br> Integer number = (integer) str; // COLLECTION ERROR: Integer and string are not in the same sequence
Comments
Post a Comment