简体   繁体   English

如何使 IntellijIDEA 与 Java 12 一起工作

[英]How to make IntellijIDEA work with Java 12

I haven't used Java for quite some time, and today I wanted to re-start using it.我已经有一段时间没有使用 Java,今天我想重新开始使用它。 So I updated my IDE (IntellijIDEA) to 2019.1.3 version 1 , and I downloaded Java 12 .所以我将我的 IDE (IntellijIDEA) 更新到2019.1.3 version 1 ,并下载了Java 12 Then I proceeded to uninstall my old Java 8 (and I deleted the folder with the SDK of Java 8 from my PC with Windows 10).然后我继续卸载旧的 Java 8(并从装有 Windows 10 的 PC 中删除了带有 Java 8 SDK 的文件夹)。

Then I opened IntellijIDEA, File -> Project Structure... -> Project -> Edit (Project SDK) and there I selected the folder where I had just installed Java 12 ( C:\\Program Files\\Java\\jdk-12.0.1 ).然后我打开 IntellijIDEA, File -> Project Structure... -> Project -> Edit (Project SDK)然后我选择了刚刚安装 Java 12 的文件夹( C:\\Program Files\\Java\\jdk-12.0.1 )。 In the same window where I edited the SDK I set Project language level to 12 - no new language features .在我编辑 SDK 的同一窗口中,我将Project language level设置为12 - no new language features

Then I went to File -> Project structure -> Modules -> Dependencies and I checked that Module SDK switched to 12 - no new language features .然后我转到File -> Project structure -> Modules -> Dependencies并检查Module SDK切换到12 - no new language features And indeed it did.确实如此。

I clicked on Apply and then OK .我点击Apply ,然后点击OK

Then I went to File -> Settings... -> Build, Execution, Deployment -> Compiler -> Java Compiler and I set Project bytecode version to 12 .然后我转到File -> Settings... -> Build, Execution, Deployment -> Compiler -> Java Compiler并将Project bytecode version设置为12

I clicked on Apply and then OK .我点击Apply ,然后点击OK

I closed IntellijIDEA and shut down my PC.我关闭了 IntellijIDEA 并关闭了我的电脑。 Then I turned my PC back on, I re-opened IntellijIDEA, I typed var and IntellijIDEA told me: Cannot resolve symbol 'var' .然后我重新打开我的电脑,我重新打开 IntellijIDEA,我输入var和 IntellijIDEA 告诉我: Cannot resolve symbol 'var'

I've found a lot of people with my issue by searching on Google, but none of them actually managed to resolve my problem.通过在 Google 上搜索,我发现很多人遇到了我的问题,但实际上没有一个人能够解决我的问题。 Here there are some question on Stack Overflow I've already read:这里有一些关于堆栈溢出的问题我已经读过:


1 1

IntelliJ IDEA 2019.1.3 (Community Edition) IntelliJ IDEA 2019.1.3(社区版)

Build #IC-191.7479.19, built on May 28, 2019 Build #IC-191.7479.19,建于 2019 年 5 月 28 日

JRE: 1.8.0_202-release-1483-b58 amd64 JRE:1.8.0_202-release-1483-b58 amd64

JVM: OpenJDK 64-Bit Server VM by JetBrains sro JVM:JetBrains sro 的 OpenJDK 64 位服务器 VM

Windows 10 10.0视窗 10 10.0

Ok, the problem was that I'm lazy and that, in my humble opinion, the error message displayed by IntellijIDEA isn't very accurate.好吧,问题是我很懒惰,而且在我看来,IntellijIDEA 显示的错误消息不是很准确。

I tried to build the project, and in the log I get a different error message: Java 'var' is not allowed here.我尝试构建该项目,但在日志中我收到一条不同的错误消息: Java 'var' is not allowed here.

Of course var isn't allowed to infer the type to a class field, but when I tried it in a method, all is fine.当然var不允许推断类字段的类型,但是当我在方法中尝试它时,一切都很好。

My fault, I wanted to check very fast if the switch to Java 12 has occured and I didn't think I couldn't use that construct in that place.我的错,我想非常快速地检查是否切换到 Java 12 并且我认为我不能在那个地方使用该构造。 By the way IntellijIDEA should have immediately showed me the "accurate" reason of the issue.顺便说一句,IntellijIDEA 应该立即向我展示问题的“准确”原因。

I should have been more careful, thanks a lot to @TituBG, @JacobG.我应该更加小心,非常感谢@TituBG,@JacobG。 and @VinceEmigh for their time!和@VinceEmigh 他们的时间!

如果您的IntelliJ版本支持,请在语言级别设置https://www.jetbrains.com/help/idea/project-page.html中启用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM