Pattern Matching for Switch

This feature is available in preview from Java 17.

Ensure your SDK and Language Level are at least Java 17 (Preview) in your Project Structure with ⌘; (macOS) / Ctrl+Alt+Shift+S (Windows/Linux).

IntelliJ IDEA highlights code that can be replaced with a switch expression using pattern variables. Press ⌥⏎ (macOS) / Alt+Enter (Windows/Linux) and choose "Replace if with switch".

Interested in JVM Development?

call to action image

You can also use pattern matching for instanceof!

Learn More


Related Resources

Inject a Language
Inject a Language
Language injections let you work with pieces of code in other languages embedded in your code.
Migrating from the `javax` to `jakarta` namespace
Migrating from the `javax` to `jakarta` namespace
How to transition your application from Java EE to Jakarta EE.
Create an Editor Fold
Create an Editor Fold
Create an editor fold to hide parts of your class which can make it more readable.