P
Paul Tomblin
I have some existing code that uses the classic old
class Playlist
{
public static final int PLAYLISTTYPE_FEATURE = 1;
public static final int PLAYLISTTYPE_TRAILER = 2;
...
But now that we're using Java 1.5, I've got new code where I decided to
use a Java 1.5 enum:
public enum PlaylistType
{
FEATURE(1, "Feature"),
TRAILER(2, "Trailer"),
....
final int id;
final String name;
PlaylistType(final int id, final String name)
{
this.id = id;
this.name = name;
}
public int getID()
{
return id;
}
public String toString()
{
return name;
}
}
In order to make sure the new code and the old code work together, I
changed the definition of the old ints to
public static final int PLAYLISTTYPE_FEATURE = PlaylistType.FEATURE.getID();
public static final int PLAYLISTTYPE_TRAILER = PlaylistType.TRAILER.getID();
Note that they're still "public static final".
But now case statements that worked before the change are breaking with
Eclipse complaining that "case expressions must be constant expressions".
Huh? They sure look constant to me. How could it think that
PLAYLISTTYPE_FEATURE could change values when it's declared final?
class Playlist
{
public static final int PLAYLISTTYPE_FEATURE = 1;
public static final int PLAYLISTTYPE_TRAILER = 2;
...
But now that we're using Java 1.5, I've got new code where I decided to
use a Java 1.5 enum:
public enum PlaylistType
{
FEATURE(1, "Feature"),
TRAILER(2, "Trailer"),
....
final int id;
final String name;
PlaylistType(final int id, final String name)
{
this.id = id;
this.name = name;
}
public int getID()
{
return id;
}
public String toString()
{
return name;
}
}
In order to make sure the new code and the old code work together, I
changed the definition of the old ints to
public static final int PLAYLISTTYPE_FEATURE = PlaylistType.FEATURE.getID();
public static final int PLAYLISTTYPE_TRAILER = PlaylistType.TRAILER.getID();
Note that they're still "public static final".
But now case statements that worked before the change are breaking with
Eclipse complaining that "case expressions must be constant expressions".
Huh? They sure look constant to me. How could it think that
PLAYLISTTYPE_FEATURE could change values when it's declared final?