I am trying to use the enhanced switch block that was standardized in Java 14. The old version is this:
switch (expression) {
case OPTION1:
foo();
break;
case OPTION2:
bar();
break;
}
however since I am using Java 14, I should be able to use this:
switch (expression) {
case OPTION1 -> foo();
case OPTION2 -> bar();
}
Here is a MRE:
public class Main {
public static void main(String[] args) {
String demo = Math.random() > 0.5 ? "Hello": "World";
switch (demo) {
case "Hello" -> System.out.println("The string contained Hello");
case "World" -> System.out.println("The string contained World");
}
}
}
When I write that code, IntelliJ gives me the following warning:
Enhanced 'switch' blocks are not supported at language level '14'
However, that warning, despite being highlighted in red to indicate a compile time error, is incorrect. The code compiles correctly and the switch block works as intended because I am using Java 14. Why am I getting this warning?
Edit: Project structure per request
Edit: My iml file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$USER_HOME$/Downloads/MathParser.org-mXparser-v.4.4.0/MathParser.org-mXparser-v.4.4.0/bin/jdk13/MathParser.org-mXparser-v.4.4.0-jdk13.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>






