0

Ok, this is very, very strange, and annoying.
I declared this variable in my IDE:

long me = 2323237777777;

And I get a compilation error saying that the literal 2323237777777 of type int is out of range. I don't understand. Isn't long supposed to be able to handle this type of range??

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by glenak
0

Yes but this: 2323237777777 is an int. And int numbers can not handle that; it is too big.
This is a long: 2323237777777L

long me = 2323237777777L;
0

When you declare and assign a long variable like

long me = xxxxx

without specifying the L in the right, it will first treat the literal as int and
then upcast it to long.
As the literal you used, is out of scope of int type, it gives that compilation error.
If you declare as

long me = xxxxxL

it treats the literal as long, hence no compilation error.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.