I have a question regarding the conversion from int into long in java.
Why for floats there is no problem:
float f = (float)45.45;//compiles no issue.
float f = 45.45f; //compiles no issue.
However for the long type it seems to be a problem:
long l = (long)12213213213;
//with L or l at the end it will work though.
long l = (long)12213213213L;
It seems that once the compiler notify an error due to an out-of-range issue it blocks there without checking for any possible casting that the programmer might have planned.
What’s your take on it? Why is it like that there is any particular reason?
Thanks in advance.
Java doesn’t consider what you do with a value only what it is. For example if you have a long value which is too large it doesn’t matter that you assign it to a double, the long value is checked as valid first.