Java - switch case, Multiple cases call the same function

前端 未结 3 1554
陌清茗
陌清茗 2020-12-20 12:28

Since I have multiple String cases which should be handled the same way, I tried:

switch(str) {
// compiler error
case \"apple\", \"orange\", \"         


        
3条回答
  •  攒了一身酷
    2020-12-20 13:09

    Java supports fall-through when you have no break:

    case "apple":
    case "orange":
    case "pieapple":
        handleFruit();
        break;
    

提交回复
热议问题