-2

I wonder why I am getting compilation error 'out of range'.

Long l =004055158L;//giving The literal 004055158L of type long is out of range.

Long l =404055158L;//no compilation error
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
S Singh
  • 1,403
  • 9
  • 31
  • 47

1 Answers1

4

It's out of range because a numeric literal with leading 0s is treated as an octal number (radix 8), in which the digit 8 is not valid.

Changing it to

Long l = 004055157L;

will remove the compilation error. Of course, there's no point to have leading 0s unless you actually want an octal number.

Eran
  • 387,369
  • 54
  • 702
  • 768