Java Switch Statement

后端 未结 8 2239
南笙
南笙 2021-02-07 13:48

I have a problem using switch statement when I tried to deal with a special situation. For example, I have 3 cases: A, B, C.

  • for A, I want to do statement_1 and st
8条回答
  •  情歌与酒
    2021-02-07 14:09

    If a case has more than 2-3 statements it's bette(from point of view of readability and clean code) to extract them as separate methods:

    switch (variable){
        case A: handleCaseA(); break;
        case B: handleCaseB(); break;
        default: handleDefaultCase(); break;
    }
    

提交回复
热议问题