更新时间:2023-09-15 17:43:52
支持开关表达式的IntelliJ最早版本是2019.1版本,该版本于2019年3月27日发布.您可以在此处获取: https://www.jetbrains.com/idea/download .当然,您还需要JDK 12,并将其设置为项目SDK.
The earliest version of IntelliJ that supports switch expressions is version 2019.1, which was released on March 27, 2019. You can get it here: https://www.jetbrains.com/idea/download . You also need JDK 12 of course, and set that as your project SDK.
然后您可以将语言级别设置为:
Then you can set the language level to:
12 (Preview) - Switch expressions
有了它,一切都会正常工作.
With that, everything should work.
如果没有,则可能要检查您是否已经拥有;
If it doesn't, you might want to check that You've;
将我的评论变成答案.您可以通过以下操作将--enable-preview
标志添加到VM:
Turning my comment into an answer. You can add the --enable-preview
flag to the VM by going to:
运行-> 编辑配置...
然后从左侧的树菜单中选择您的主类,然后将--enable-preview
粘贴到"VM options"(虚拟机选项)中.盒
Then selecting your main class from the tree menu on the left, and pasting --enable-preview
in the "VM options" box
您可以通过以下步骤对编译器执行相同操作:
You can do the same for the compiler by going to:
文件-> 设置...
然后在树菜单中的 Build,Execution,Deployment ->下. 编译器-> Java编译器,您可以将--enable-preview
放入其他命令行参数"框:
Then in the tree menu under Build, Execution, Deployment -> Compiler -> Java Compiler you can put --enable-preview
in the "Additional command line parameters" box:
请注意,执行此操作后,Intellisense仍然可能无法正常工作.我仍然在->
下看到红色的波浪线,并显示错误消息意外的令牌".但是,当我单击运行按钮时,该类将编译并运行正常.
Note that intellisense still might not work after doing that. I'm still seeing red squiggly lines under the ->
s with the error message "unexpected token". But, when I click the run button the class compiles and runs just fine.