-
Bug
-
Resolution: Fixed
-
P4
-
1.1, 1.1.4, 1.3.0
-
kestrel
-
generic, sparc
-
generic, solaris_2.5.1
Name: tb29552 Date: 08/27/99
/*
A bug was reported against Metamata Audit because it rejected a
case label as non-constant and javac did not. Checking the JLS,
it appears that Audit is correct and javac should, in fact,
reject it.
Here is the program:
*/
import java.awt.event.MouseEvent;
public class CaseTest {
public void processMouseEvent (MouseEvent event) {
switch (event.getID ()) {
case MouseEvent.MOUSE_PRESSED: // OK
break;
case event.MOUSE_RELEASED: // Not constant by JLS 15.27
break;
}
}
}
/*
JLS ?14.9, the grammar defines SwitchLabel as either "case
ConstantExpression :" or "default :". The text says "These
labels are said to be associated with the switch statement, as
are the values of the constant expressions (?15.27) in the case
labels."
In JLS ?15.27, a ConstantExpression is defined as one of 13
choices, only the last of which can be a qualified name:
"Qualified names of the form TypeName.Identifier that refer to
final variables whose initializers are constant expressions"
*/
(Review ID: 94481)
======================================================================
- duplicates
-
JDK-4119776 illegal 'case' constant expressions
- Closed