Why is -1001 not a valid Java integer literal?

In Java, -1001 not considered a valid integer literal. Why?

+6
source share
2 answers

There is no such thing as a negative decimal literal in Java; see JLSยง3.10.1 .

-1001 is a constant expression evaluating compilation time, consisting of the unary negation of the letter 1001.

(The same goes for C and C ++).

+10
source

The number -1001 is a valid integer literal in java 7 and above.

+1
source

All Articles