James Raitsev
James Raitsev

Reputation: 96491

Java 7 Syntax error

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

Upvotes: 4

Views: 503

Answers (2)

Andy Harris
Andy Harris

Reputation: 938

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).

Upvotes: 5

Ray Toal
Ray Toal

Reputation: 88448

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

Upvotes: 5

Related Questions