Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a hot key or easy way to replace an if-else if statement with a switch in IntelliJ? I would prefer not to manually convert the if-else if statement to a switch. I am looking to be able to highlight the if-else if statement and press a combination of keys or use a menu button.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
502 views
Welcome To Ask or Share your Answers For Others

1 Answer

Update: as @christopheml pointed out in comments on another answer, "Replace If with Switch" seems to have disappeared in IntelliJ 2018.1. A bug has been filed here.


There are IntelliJ intentions named "Replace If with Switch" and "Replace Switch with If". Check your preferences to see if those options are enabled. If so, I would expect that you would see a quickfix option (Option+Enter on Mac, Alt+Enter on Windows) whenever IntelliJ can automatically handle the conversion from one to the other.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...