Skip to content
Advertisement

Arrow in case statement supported from Java 14 onwards only Java compilation error

I am new to Java. I am using Eclipse IDE, using the following config:

java.runtime.name=OpenJDK Runtime Environment
java.runtime.version=16.0.1+9-24

I do have simple switch statement:

 var forecastedAmount = amount * switch (dealStage) {
            case LEAD -> 0.2;
            case EVALUATING -> 0.5;
            case INTERESTED -> 0.8;
            case CLOSED -> 1;
        };

But I get compilation error as:

Arrow in case statement supported from Java 14 onwards only

Why is that?

Advertisement

Answer

Capturing my earlier comment as an answer for future reference: You should check the project properties and make sure you’re using Java 16 in the build path.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement