Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: Generate switch case

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.

like image 556
Stefan Hoth Avatar asked Sep 19 '12 00:09

Stefan Hoth


People also ask

Can you create switch statement using enum?

We can use also use Enum keyword with Switch statement. We can use Enum in Switch case statement in Java like int primitive.

Can we use enum in Switch Case C?

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.

Can we have multiple cases in switch?

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.


1 Answers

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.

Intention: Create Enum Switch Branches

See YouTrack issue 6374.

like image 91
Christopher Peisert Avatar answered Sep 18 '22 20:09

Christopher Peisert