I'm engaged in Java14 features in these days. I could write a code snippet about switch case and I created a dynamic web project to use this command --enable-preview to run any code based on Java14 but I have a problem about it. I tried many things to solve it out but nothing changed. How can I fix it out?
Here is my error appeared on the console.
Error: LinkageError occurred while loading main class switchcase1.SwitchMain
java.lang.UnsupportedClassVersionError: switchcase1/SwitchMain (class file version 57.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 58.65535
Here is my code snippet
private static void getDayInJava14(int day) {
// TODO Auto-generated method stub
switch (day) {
case 1-> {
System.out.println("Monday");
}
case 2-> {
System.out.println("Tuesday");
}
case 3-> {
System.out.println("Wednesday");
}
case 4 -> System.out.println("Thursday");
case 5 -> System.out.println("Friday");
case 6 -> System.out.println("Saturday");
case 7 -> System.out.println("Sunday");
default -> System.out.println("Invalid day");
}
}
Here is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>002_Java_Switch</groupId>
<artifactId>002_Java_Switch</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>14</java.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>${java.version}</release>
<compilerArgs>
--enable-preview
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>