This Java switch statement doesn’t work on with my IntelliJ settings. Can someone help me point to the right portions of IntelliJ where I can solve this problem?
Intelij displays error message:
error: illegal start of expression return switch (setType) {
when running this code:
private static SimpleAbstractSet<String> makeSet(String setType){
return switch (setType) {
case "HashSet" -> new SimpleHashSet<>();
case "TreeSet" -> new SimpleTreeSet<>();
...
default -> throw new IllegalArgumentException();
};
}
The code I’m using is from the MOOC “Functional Programming with Java and Threads from the vanderBiltUniveristy. It is on https://github.com/douglascraigschmidt/ and does work with them. Therefore I’m looking in my environment and IDE setup to see if I can find the error.
Linux CentOS
- java version 21.0.4
- gradle version 8.4
- JAVA_HOME=/usr/lib/jvm/jdk-21.0.4-oracle-x64
- GRADLE_HOME=/opt/gradle/gradle-8.4
- PATH=/opt/gradle/gradle-8.4/bin:/usr/lib/jvm-21.0.4-oracle-x64/bin:…..
InteliJ Project Structure
- SDK: 21 Oracle OpenJDK 21.0.4
- Language level 21- Record patterns,…..
- JDK home path /usr/lib/jvm/jdk-21.0.4-oracle-x64
InteliJ Project Settings
- Gradle user home /opt/gradle/gradle-8.4
- Gradle JVM JAVA_HOME
gradle-wrapper.properties
- …
- distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip
- …
build gradle
group 'livelessons'
version '1.0-SNAPSHOT'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.jsoup:jsoup:1.14.3'
}
Solution
InteliJ Setting | Build Tools | Gradle
every example of the MOOC is a separate gradle project. For reasons I do not know some of the projects are set by inteliJ to use Gradle JVM 11. These need to be set to JAVA_HOME Oracle OpenJDK 21.0.4
14
Solution
InteliJ Setting | Build Tools | Gradle
Every example of the MOOC is a separate gradle project. For reasons I do not know some of the projects are set by inteliJ to use Gradle JVM 11. These need to be set to JAVA_HOME Oracle OpenJDK 21.0.4