Pattern Matching for Switch

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".


Related Resources

Inject a language
Inject a language
Language injections let you work with pieces of code in other languages embedded in your code.
Generate constructors and accessor methods
Generate constructors and accessor methods
Quickly generate common code constructs such as Constructors, Getters and Setters
Expand and Collapse Code
Expand and Collapse Code
Quickly view specific parts of a class by expanding or collapsing code