Could anyone please tell me why the following casting is resulting in compile time error:
Long l = (Long)Math.pow(5,2);
But why not the following:
long l = (long)Math.pow(5,2);
Math.pow(5,2)
is a double
, which can be cast to long
. It can not be cast to Long
.
This would however work fine, thanks to autoboxing which converts between long
and Long
:
Long l = (long)Math.pow(5,2);
To summarize, you can convert double --> long
and long --> Long
, but not double --> Long
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