Combine return and switch
问题 How can I combine return and switch case statements? I want something like return switch(a) { case 1:"lalala" case 2:"blalbla" case 3:"lolollo" default:"default" }; I know about this solution switch(a) { case 1: return "lalala"; case 2: return "blalbla"; case 3: return "lolollo"; default: return "default"; } But I want to only use the return operator. 回答1: switch and return can't combine that way, because switch is a statement , not an expression (i.e., it doesn't return a value). If you