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??

Recommended Answers

All 3 Replies

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;

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.

aaah i see. Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.