I keep getting the syntactic error in Java code:
Cannot cast from Object to int.
The problem code is like this:
int a = (int)obj;//obj is of Object type
But I have always been using this trick around, and only get the error recently.
My question:
Object to int is two steps - first you need to convert the Object to an Integer, then you need to convert the Integer to an int.
Fortunately auto-boxing will handle the second conversion for you, but you still need to explicitly make the first conversion:
int a = (Integer)obj;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With