Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is -1001 not a valid Java integer literal?

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

like image 288
Ana S Avatar asked Aug 19 '16 07:08

Ana S


2 Answers

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

-1001 is an compile time evaluable constant expression consisting of a unary negation of the literal 1001.

(The same applies to C and C++).

like image 188
Bathsheba Avatar answered Oct 12 '22 06:10

Bathsheba


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

like image 45
David Avatar answered Oct 12 '22 07:10

David