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);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Math.pow(5,2)is adouble, which can be cast tolong. It can not be cast toLong.This would however work fine, thanks to autoboxing which converts between
longandLong:To summarize, you can convert
double --> longandlong --> Long, but notdouble --> Long