var keyword not reconized in JDK 10

前端 未结 2 775
耶瑟儿~
耶瑟儿~ 2021-01-15 00:33

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

相关标签:
2条回答
  • 2021-01-15 01:17

    If you are using maven project, make sure that maven.compiler.source and maven.compiler.target are all pointing to 10.

        <properties>
           <maven.compiler.source>10</maven.compiler.source>
           <maven.compiler.target>10</maven.compiler.target>
        </properties>
    
    0 讨论(0)
  • 2021-01-15 01:33

    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.
    0 讨论(0)
提交回复
热议问题