Huzzah!
This code worked for a time, then I decided to add a default color, and it stopped working. I get the following error:
1 error found:
File: Status.java [line: 20]
Error: Status.java:20: illegal reference to static field from initializer
With the following code at compile-time.
import java.awt.Color;
enum Status
{
OFF ("Off"),
TRAINING ("Training", new Color(255, 191, 128)),
BEGINNER ("Beginner", new Color(128, 255, 138)),
INTERMEDIATE ("Intermediate", new Color(128, 212, 255)),
ADVANCED ("Advanced", new Color(255, 128, 128));
public final String name;
public final Color color;
public static final Color defaultColor = Color.WHITE;
Status(String name)
{
this(name, defaultColor);
}
Status(String name, Color color)
{
this.name = name;
this.color = color;
}
}
This should work, as far as I can tell, but for whatever reason Java decided to throw an error. Any thoughts?
defaultColor
field? Shouldn't the rest of your code just look atStatus.color
anyway? – Brad Mace Jun 22 '11 at 5:31