Avoiding multiple If statements in Java

后端 未结 13 857
北恋
北恋 2020-12-30 07:52

I\'ve coded a method something like this. But I guess this should undergo refactoring. Can any one suggest the best approach to avoid using this multiple if statements?

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 08:06

    There is no way to evade that in general. In your case - if there is a set of allowed extensions - you could create an Enum, convert the extension to the Enum type via valueOf(), and then you can switch over your enum.

提交回复
热议问题