How to suppress Java compiler warnings for specific functions

前端 未结 5 879
暗喜
暗喜 2020-12-03 10:28

We are always taught to make sure we use a break in switch statements to avoid fall-through.

The Java compiler warns about these situations to help us not m

5条回答
  •  猫巷女王i
    2020-12-03 10:47

    To complete other answer about SuppressWarnings:

    @SuppressWarnings("fallthrough")
    

    Try to supress all the fall-through warning at the compiler level is a bad thing: as you've explained, the cases where you need to pass through the warning are clearly identified. Thus, it should be explicitly written in the code (the @SuppressWarnings("fallthrough") annotation with an optionnal comment is welcome). Doing so, you'll still have the fall-through warning if you really forget a break somewhere elese in your code.

提交回复
热议问题