Saibabaa Pragada wrote:
This doesn't work in the same way as castig primitives (char to byte, byte to int, int to long etc.).
If an object of given class is created, it will stay an object of this class
forever - it is not possible to change the class of any object.
You cannot "upcast" the object - it is not possible.
Look at this simple example:
Output is:
As You see - "upcasting" doesn't work, the class of the object does not change.
If you want to "change" a class of exception "t" to RuntimeException, instead of casting you can wrap the exception t into the RuntimeException in this way: