Java Reference
In-Depth Information
od, and this contract must be upheld whether assertions are enabled or dis-
abled.
Another problem with using assertions for argument checking is that erroneous
arguments should result in an appropriate run-time exception (such as
IllegalAr-
gumentException
,
ArrayIndexOutOfBoundsException
, or
NullPointerException
). An as-
sertion failure will not throw an appropriate exception. Again, it is not illegal
to use assertions for argument checking on
public
methods, but it is generally
inappropriate. It is intended that
AssertionError
never be caught, but it is possible
to do so, thus the rules for
try
statements should treat assertions appearing in a
try
block similarly to the current treatment of
throw
statements.
14.11. The
switch
Statement
The
switch
statement transfers control to one of several statements depending on the value
of an expression.
SwitchStatement:
switch (
Expression
)
SwitchBlock
SwitchBlock:
{
SwitchBlockStatementGroups
opt
SwitchLabels
opt
}
SwitchBlockStatementGroups:
SwitchBlockStatementGroup
SwitchBlockStatementGroups SwitchBlockStatementGroup
SwitchBlockStatementGroup:
SwitchLabels BlockStatements
SwitchLabels:
SwitchLabel
SwitchLabels SwitchLabel
SwitchLabel:
case
ConstantExpression
:
case
EnumConstantName
:
default :
EnumConstantName:
Identifier
The type of the
Expression
must be
char
,
byte
,
short
,
int
,
Character
,
Byte
,
Short
,
Integer
,
String
, or
an enum type (ยง
8.9
), or a compile-time error occurs.
The body of a
switch
statement is known as a
switch block
.