Back to Intellij Community

SwitchStatementWithConfusingDeclaration

java/java-impl/resources/inspectionDescriptions/SwitchStatementWithConfusingDeclaration.html

2025.3-rc-2314 B
Original Source

Reports local variables declared in one branch of a switch statement and used in another branch. Such declarations can be extremely confusing.

Example:

switch(i) {
      case 2:
          int x = 0;
          break;
      case 3:
          x = 3;
          System.out.println(x);
          break;
    }