• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to initialize long variable '012345678L'. The literal 012345678L of type long is out of range  RSS feed

 
Balaji Krishnan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to initialize long variable for the value '012345678L', getting the below error message


Error:
The literal 012345678L of type long is out of range

Whereas i am able to initialize the value '+123456780L'. Please clarify me why i am the getting the error for the above variable declaration.

 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balaji Krishnan wrote:I am unable to initialize long variable for the value '012345678L', getting the below error message


Error:
The literal 012345678L of type long is out of range

Whereas i am able to initialize the value '+123456780L'. Please clarify me why i am the getting the error for the above variable declaration.


If you put a 0 (zero) at the start of a literal integer, the compiler assumes it is an octal representation of the number and 8 is not a valid digit in octal numbers.
 
Balaji Krishnan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your explanation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!