Search code examples
javanetbeansjava-10

var keyword not reconized in JDK 10


I have installed netbeans (Apache version) with JDK 10 successfully, but can't use var keyword in my project, It keep saying cannot find symbol. Any help would be appreciated.


Solution

  • To use the var keyword with JDK 10 in NetBeans:

    • Ensure that you are running the latest version of Apache NetBeans.
    • In NetBeans add JDK 10 as a Java platform (Tools > Java Platforms > Add Plaform...). It is not necessary to make JDK 10 the default.
    • Create a simple Java application (File > New Project... > Java > Java Application) and declare a var variable (e.g. var v = 7;) within the main() method.
    • Select the project node in the Projects pane, right click and select Properties.
    • In the Project Properties window ensure that Libraries > Java Platform is set to JDK 10
    • In the Project Properties window ensure that Sources > Source/Binary Format is set to JDK 10
    • In the Files pane open the file project.properties (under the nbproject folder) and navigate to the lines for javac.source and javac.target. Verify that they both contain the value 10.
    • Press Shift-F11 to clean and build the project.

    If there is still a "cannot find symbol" error for the var declaration then there is something fundamentally wrong with the NetBeans installation, so update the OP with:

    • The content of the Output window after doing the Clean and Build.
    • The source being compiled.
    • The settings for javac.source and javac.target in project.properties.
    • The version information shown in the Help > About window.