IntelliJ IDEA no code completion for Java 10 'var'?

房东的猫 提交于 2019-12-30 06:27:56

问题


Recently I installed the new version (2018.1) of IntelliJ IDEA, which added support for Java 10.

But when I trying to use the var (for local variable type inference), I found there was no var in the code completion list. (See the screenshot below)

If I continue typing, it will apply VarHandle as the first suggestion in that list. Then I have to undo that completion to restore var.

I have checked project settings, I use JDK 10 and the language level is also set to 10. Code like var number = 1; compiles well. And I couldn't find anything about this in IDE settings.

What am I doing wrong? I just want to use var declaration without interruption.


回答1:


As @Vic pointed out, this appears to be a bug. Until it gets fixed, you can create a custom live template as a workaround.

Create a live template triggered by the var abbreviation, then enter var as the template text. Make it available in the Java statement context.




回答2:


Issue has been fixed in upcoming IntelliJ IDEA 2018.2 release:

https://www.jetbrains.com/idea/nextversion/ (currently EAP version)



来源:https://stackoverflow.com/questions/49719299/intellij-idea-no-code-completion-for-java-10-var

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