Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 7 Syntax error

Tags:

java-7

I have Java 7 running on my mac:

    System.out.println(System.getProperty("java.version")); // prints 1.7.0_05

Project was created using

enter image description here

Project properties confirm, i am on Java 7

enter image description here

Default system Java is 7

enter image description here

The following however results in syntax error

public static void main(String[] args) {    
    // Underscores in Numeric Litarals are ok here  
    int i = 11_234;
}

Eclipse is complaining with Syntax error on token "_234", delete this token

like image 318
James Raitsev Avatar asked Dec 27 '22 21:12

James Raitsev


2 Answers

On Eclipse's Project|Properties dialog, there two entities Java Build Path and Java Compiler. The former will tell you what classes are used during the build, and you may have a Java 7 JRE listed there. The latter, however, is the compiler that will be used to compile your code. It is possible to have Eclipse use a Java 6 compiler even with a Java 7 JRE on the build path.

My guess is that you are using Helios, not Indigo. See Programming Java 7 in Eclipse

like image 74
Ray Toal Avatar answered Mar 13 '23 06:03

Ray Toal


Make sure your version of Eclipse is 3.7.1 (this is Eclipse 3.7 Maintenance Build) or higher (see JDT/Eclipse Java 7 Support) and that you have registered Java 7 with Eclipse (see Eclipse and Java 7).

like image 37
Andy Harris Avatar answered Mar 13 '23 04:03

Andy Harris