Switch cases maximum implementation?

前端 未结 7 1662
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 12:27

I am using a single switch cases which will have more than 100 cases statement to be used. Are there any limit ?

The usage of cases are for the suggestions of my Aut

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 13:12

    Switch works fine with byte, short, char, and int. So you have the limitation of int values + default. From here

    But I suggest to think more on architecture. It is better to organize some interface 'performer' and implement some number of that performer (could be as inner classes). Then you only need to have an array(map) where you will have the conditions and instances of this performers. The idea is to separate the data from algorithm.

    Also yo may try to find other patterns for that

提交回复
热议问题