E
exquisitus
I'm using JDK (1.4) and cannot use JDK 1.5 for my current project.
I have wrapped up an enumeration in a class as ff:
public final class myEnum {
private String id ;
public final int ord ;
private static int enumCount = 0 ;
private myEnum prev ;
private myEnum next ;
private static myEnum first = null ;
private static myEnum last = null ;
/* Enums */
public static final myEnum ENUM_ONE = new myEnum("Enum1") ;
public static final myEnum ENUM_TWO = new myEnum("Enum2") ;
.....
private myEnum(String newId) {
this.id = newId ;
this.ord = enumCount++ ;
if ( first == null ) first = this ;
if ( last != null) {
this.prev = last ;
last.next = this ;
}
last = this ;
}
..... etc.
..... etc.
};
I am using this Enum class in a switch statement as follows:
foo (MyEnum e, ....) {
switch (e.ord)
{
case myEnum.ENUM_ONE.ord:
...
break;
case myEnum.ENUM_TWrd:
...
break;
......etc
}
}
I get the ff compile time error: "case expressions must be constant
expressions". I know that - but hasn't ord being initialized as a
'constant' for each instance of my enumeration?
What am I doing wrong ?. How can I fix it so I can use my enumerations
in a case statement as shown in the foo() function above.
Thanks
I have wrapped up an enumeration in a class as ff:
public final class myEnum {
private String id ;
public final int ord ;
private static int enumCount = 0 ;
private myEnum prev ;
private myEnum next ;
private static myEnum first = null ;
private static myEnum last = null ;
/* Enums */
public static final myEnum ENUM_ONE = new myEnum("Enum1") ;
public static final myEnum ENUM_TWO = new myEnum("Enum2") ;
.....
private myEnum(String newId) {
this.id = newId ;
this.ord = enumCount++ ;
if ( first == null ) first = this ;
if ( last != null) {
this.prev = last ;
last.next = this ;
}
last = this ;
}
..... etc.
..... etc.
};
I am using this Enum class in a switch statement as follows:
foo (MyEnum e, ....) {
switch (e.ord)
{
case myEnum.ENUM_ONE.ord:
...
break;
case myEnum.ENUM_TWrd:
...
break;
......etc
}
}
I get the ff compile time error: "case expressions must be constant
expressions". I know that - but hasn't ord being initialized as a
'constant' for each instance of my enumeration?
What am I doing wrong ?. How can I fix it so I can use my enumerations
in a case statement as shown in the foo() function above.
Thanks