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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -