Syntax of switch Statement (see Java Language Specification, section 13.9)
does not allow using statements without 'case' in switch block:
SwitchStatement:
switch ( Expression ) SwitchBlock
SwitchBlock:
{ SwitchBlockStatements_opt }
SwitchBlockStatements:
SwitchBlockStatement
SwitchBlockStatements SwitchBlockStatement
SwitchBlockStatement:
SwitchLabels BlockStatements
SwitchLabels
SwitchLabel
SwitchLabels SwitchLabel
SwitchLabel
case ConstantExpression :
default :
But Java compiler don't consider this as an error and
compiles such switch statement successfully.
See example below:
> cat stmt107.java
public class stmt107
{
public static void main(String args[])
{
int b = 2;
for ( b = 1; b < 4; b++ )
{
switch ( b )
{
System.out.println("nothing");
}
System.out.println("PASS " + b);
}
}
}
> /usr/local/java/1.0/bin/javac stmt107.java
> /usr/local/java/1.0/bin/java stmt107
PASS 1
PASS 2
PASS 3
>
does not allow using statements without 'case' in switch block:
SwitchStatement:
switch ( Expression ) SwitchBlock
SwitchBlock:
{ SwitchBlockStatements_opt }
SwitchBlockStatements:
SwitchBlockStatement
SwitchBlockStatements SwitchBlockStatement
SwitchBlockStatement:
SwitchLabels BlockStatements
SwitchLabels
SwitchLabel
SwitchLabels SwitchLabel
SwitchLabel
case ConstantExpression :
default :
But Java compiler don't consider this as an error and
compiles such switch statement successfully.
See example below:
> cat stmt107.java
public class stmt107
{
public static void main(String args[])
{
int b = 2;
for ( b = 1; b < 4; b++ )
{
switch ( b )
{
System.out.println("nothing");
}
System.out.println("PASS " + b);
}
}
}
> /usr/local/java/1.0/bin/javac stmt107.java
> /usr/local/java/1.0/bin/java stmt107
PASS 1
PASS 2
PASS 3
>
- duplicates
-
JDK-4030953 Switch implemented incorrectly
-
- Closed
-
-
JDK-4013503 JCK102a: different status -- lang/errors/stat_not_reached tests
-
- Closed
-