Why can't it start from scratch?

Possible duplicate:
09 not recognized, where recognized 9

Just wondering when I declare the following:

public static final long __VERSIONCODE = 0L; public static final long __VERSIONCODE = 9L; 

which will work, but whenever I try to do this:

 public static final long __VERSIONCODE = 09L; public static final long __VERSIONCODE = 08235L; 

I get an error (in eclipse):

"Type 09L type long is out of range.

So I thought it happened because it started from scratch.

but then I tried the second digit below eight:

 public static final long __VERSIONCODE = 07235L; 

which does not give me errors.

then

 public static final long __VERSIONCODE = 07239L; 

also causes an error.

So I really donโ€™t understand what values โ€‹โ€‹I can assign to a long one, but I canโ€™t. Why am I getting these errors? (Actually, I'm just wondering, I can just use String for my version code).

Also, I forgot to mention that it behaves exactly the same, using doubles instead of longs.

+4
source share
2 answers

When you put 0 in front of a literal type of an integer type, it will interpret it as representing an octal number . Since "9" is not a valid digit for octal numbers, this may be what happens. Try printing the (decimal) value "010L" and see if it says "8".

Note: not sure if Java does this, or is it just an Eclipse artifact. If the latter, printing 010L, shows 10. If the former, you will see 8. If it is just an Eclipse artifact, you can confirm by trying 01L, 02L, ..., 07L, which should work, and 08L and 09L, which will fail .

+16
source

using leading zeros for constants, indicates the octal notation, according to which only digits 0..7 are allowed. therefore, if you use leading zeros to create a pretty pretty print, this is a bad idea, because the meaning it represents is different.

See http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html#3.10.1 and watch out for "OctalNumeral".

+4
source

All Articles