Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local Variable Type Inference not being recognized

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);
    }
}

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

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

like image 330
Zalán Meggyesi Avatar asked Dec 23 '22 08:12

Zalán Meggyesi


2 Answers

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.

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

like image 175
Zalán Meggyesi Avatar answered Dec 26 '22 10:12

Zalán Meggyesi


In Settings/Build/Compiler/Java Compiler you must change the "Target bytecode version" to 10 in each one of your modules.

like image 23
Alexander Galván Avatar answered Dec 26 '22 10:12

Alexander Galván