Can you use conditional statements in switch-case in Android?

前端 未结 7 1224
梦毁少年i
梦毁少年i 2021-02-09 16:07

I can\'t seem to find a straight forward yes or no to this in my searching. In Android, is there a way to use a conditional statement in case-switch? For example, with age being

7条回答
  •  野的像风
    2021-02-09 16:50

    It is not possible. Instead, Try this minimalist approach

     age > 79 ? first_case_method() 
              : age > 50 ? second_case_method() 
              : age > 40 ? third_case_method() 
              : age > 30 ? fourth_case_method() 
              : age > 20 ? fifth_case_method()
              : ... 
              : default_case_method();
    

提交回复
热议问题