-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.2.2, 6u21
-
generic, x86
-
generic, windows_7
Name: krT82822 Date: 09/28/99
According to the language specification, the "case" in a
Switch/Case statement must be a constant (i.e.
switch(x){
case A: //do stuff...
case B: //do other stuff...
default: //do default stuff...
} // A and B must be constant ints at compile time)
The typical way to define constant int is with a "public static final int"
declaration. However, sometimes we may want to put more "ooomf"
(such as strong typing and enumation capabilities) into our
constants and this requires creating constants of a particular
class (see the article in JavaWorld for a more in-depth explanation
http://www.javaworld.com/javaworld/jw-07-1997/jw-07-enumerated.html).
A brief example:
public final class EmployeeType{
public final int ord;
public static int highestOrd = 0;
private EmployeeType(){
ord = highestOrd++;
}
public static final WORKER = new EmployeeType();
public static final MANAGER = new EmployeeType();
public static final SUPERVISOR = new EmployeeType();
}
We may later on try to use EmployeeType.WORKER.ord as a constant
only to find the compiler does not consider this a constant. However,
logically, it is impossible for EmployeeType.WORKER.ord to not hold
a constant value, given the code above.
------------
9/28/99 eval1127@eng -- the "spirit" of this request is covered elsewhere, I believe, but am filing a reference RFE just to make sure.
(Review ID: 95666)
======================================================================
According to the language specification, the "case" in a
Switch/Case statement must be a constant (i.e.
switch(x){
case A: //do stuff...
case B: //do other stuff...
default: //do default stuff...
} // A and B must be constant ints at compile time)
The typical way to define constant int is with a "public static final int"
declaration. However, sometimes we may want to put more "ooomf"
(such as strong typing and enumation capabilities) into our
constants and this requires creating constants of a particular
class (see the article in JavaWorld for a more in-depth explanation
http://www.javaworld.com/javaworld/jw-07-1997/jw-07-enumerated.html).
A brief example:
public final class EmployeeType{
public final int ord;
public static int highestOrd = 0;
private EmployeeType(){
ord = highestOrd++;
}
public static final WORKER = new EmployeeType();
public static final MANAGER = new EmployeeType();
public static final SUPERVISOR = new EmployeeType();
}
We may later on try to use EmployeeType.WORKER.ord as a constant
only to find the compiler does not consider this a constant. However,
logically, it is impossible for EmployeeType.WORKER.ord to not hold
a constant value, given the code above.
------------
9/28/99 eval1127@eng -- the "spirit" of this request is covered elsewhere, I believe, but am filing a reference RFE just to make sure.
(Review ID: 95666)
======================================================================
- duplicates
-
JDK-6978894 Allow handling of object in switch statement using new Switchable interface.
-
- Closed
-
- relates to
-
JDK-4811993 RFE: Expand allowable case labels in switch statement
-
- Closed
-
-
JDK-5012262 Using Strings and Objects in Switch case statements.
-
- Closed
-
-
JDK-8061403 Allow multiple constants and ranges in case labels
-
- Closed
-
-
JDK-5029289 Extended switch statement accepting String arguments
-
- Closed
-