Home > Net >  How to use Java 19 in IntelliJ Idea community Edition
How to use Java 19 in IntelliJ Idea community Edition

Time:11-21

I am trying to use the destructuring syntax of Java 19 pattern match, but my IntelliJ Idea cannot understand it (please refer below screenshot). Is there a way to fix this? Or IntellJ is not yet ready for java 19 ?

enter image description here

    // sealed interface and record combo
    public sealed interface LoginRequest permits DefaultLogin {}
    public record DefaultLogin(@Min(1) int userId, @Valid Password password) implements LoginRequest {}

    // java 19 switch is not supported in IntelliJ Idea, gives all red lines
    Optional<Profile> profileMaybe = switch (loginRequest) {
        case DefaultLogin(int id, Password pw) -> getProfile(new ById(id));

CodePudding user response:

Yes, IntelliJ IDEA doesn't support Java 19 yet. See link.

CodePudding user response:

IntelliJ 2022.3

The early-access version of IntelliJ 2022.3 does support Java 19 as an “experimental feature”. This .3 update of IntelliJ should be formally released very soon.

This support includes the third preview of the pattern-matching with switch feature. As a preview feature, you’ll need to go out of your way to enable that functionality. And note that this feature is also previewed in Java 20, so details may be changing.

For details on the feature, see:

  • Related