无法识别局部变量类型推断 [英] Local Variable Type Inference not being recognized

查看:144
本文介绍了无法识别局部变量类型推断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了JDK 10来试用新功能,但我对var挂了很大的电话-由于某种原因,即使JDK已添加到IntelliJ(版本2018.1)中,下面的代码仍然不会编译,说Java找不到符号var:

I installed JDK 10 to try out the new features, and I got a big hung up on var - for some reason, even though the JDK was added to IntelliJ (version 2018.1), the following code still won't compile, saying Java cannot find the symbol var:

public class Variations {
    public static void main(String[] args) {
        var local = "foo";
        System.out.println(local);
    }
}

我是否在这里遗漏了一些明显的内容,或者我应该启用IntelliJ中的选项?

Am I missing something obvious here, or is there an option in IntelliJ I should enable?

项目模块 SDK和语言级别均设置为Java 10安装和lvl. 10(虽然不是X - experimental级别).

Both project and module SDK and Language Level are set to the Java 10 installation and lvl. 10 (though not the X - experimental level).

推荐答案

显然,尽管仅通过在项目和模块上将语言级别均设置为X - Experimental features一次来重新启动IDE还是不够的,但重新启动IDE还是不够的.设置为lvl. 10 足够足以使IDE恢复正常运行.

Apparently, though a hard restart of the IDE is not enough, by setting language level to X - Experimental features on both the project and the module once, then re-setting it to lvl. 10 was enough to bring the IDE back in line.

我想我应该把@CrazyCoder归功于它给了我这个主意,即使是间接的.

I guess I should credit @CrazyCoder here for giving me the idea, even if indirectly.

这篇关于无法识别局部变量类型推断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆