var keyword not reconized in JDK 10

☆樱花仙子☆ 提交于 2019-12-01 11:39:37

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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!