Using Integer in Switch Statement

后端 未结 6 1789
心在旅途
心在旅途 2020-12-10 15:05

For various business reasons I want to hold some static IDs in one of my classes. They were originally int but I wanted to change them to Integer s

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 15:53

    You must use a constant value in a switch statement.

    switch(mObj.getId()){
        case 5: //do something
        default: //do something default
    }
    

提交回复
热议问题