Is there really no way to generate a switch case for a given variable in IntelliJ?
Ctrl+Space as well as Ctrl+J yield no results.
We can use also use Enum keyword with Switch statement. We can use Enum in Switch case statement in Java like int primitive.
Example of Using Enum in Switch Case StatementWe will then use the switch case statements to switch between the direction elements and print the output based on the value of the variable for the enum directions.
The switch can includes multiple cases where each case represents a particular value. Code under particular case will be executed when case value is equal to the return value of switch expression. If none of the cases match with switch expression value then the default case will be executed.
For enum variables, enter switch (myEnumVar)
and press Alt+Enter. Smart completion will suggest: Create missing 'switch' branches
Crazy Coder provided the following screenshot showing how to enable the Create Enum Switch Branches intention.
See YouTrack issue 6374.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With