N
Novice
Can an enum make references to another enum?
I'm trying to figure out a compiler error.
I have an enum called ColorPalette which references a second enum called
ColorName. Here is a relevant excerpt from ColorName:
==============================================================
public enum ColorName {
BLACK (new Color(0, 0, 0)),
WHITE (new Color(255, 255, 255)),
PALE_GRAY (new Color(204, 204, 204)),
PALE_DULL_RED (new Color(255, 153, 153)),
/* etc... */
MEDIUM_FADED_RED (new Color(255, 51, 51));
private final Color color;
/**
* Constructor for enum ColorName.
*
* @param color the color associated with the color name.
*/
ColorName(Color color) {
this.color = color;
}
public Color getColor() { return this.color; }
}
==============================================================
Here is an excerpt of ColorPalette which illustrates how I'm using
ColorName:
==============================================================
public enum ColorPalette {
/** Constant and data for BLUES color palette. */
BLUES (ColorName.PALE_GRAY, ColorName.WHITE, ColorName.BLACK,
ColorName.PALE_WEAK_BLUE, ColorName.PALE_DULL_BLUE,
ColorName.MEDIUM_FADED_BLUE, ColorName.PALE_DULL_ORANGE,
ColorName.RED_RED_PINK),
/** Constant and data for REDS color palette. */
REDS (ColorName.PALE_GRAY, ColorName.WHITE, ColorName.BLACK,
ColorName.PALE_DULL_RED, ColorName.MEDIUM_FADED_RED,
ColorName.DARK_FADED_RED, ColorName.PALE_DULL_TEAL,
ColorName.SPRING_SPRING_GREEN),
/* etc.... */
/** The background color associated with a given color palette. */
private final ColorName backgroundColorName;
/** The light text color associated with a given color palette. */
private final ColorName textLightColorName;
/** The dark text color associated with a given color palette. */
private final ColorName textDarkColorName;
/** The light contrast color associated with a given color palette.
*/
private final ColorName contrastLightColorName;
/** The medium contrast color associated with a given color palette.
*/
private final ColorName contrastMediumColorName;
/** The dark contrast color associated with a given color palette. */
private final ColorName contrastDarkColorName;
/** The opposite color associated with a given color palette. */
private final ColorName oppositeColorName;
/** The clash color associated with a given color palette. */
private final ColorName clashColorName;
/**
* Constructor for enum ColorPalette.
*
* @param backgroundColor the background color associated with the
color palette.
* @param textLightColor the light text color associated with the
color palette.
* @param textDarkColor the dark text color associated with the color
palette.
* @param contrastLightColor the light contrast color associated with
the color palette
* @param contrastMediumColor the medium contrast color associated
with the color palette.
* @param contrastDarkColor the dark contrast color associated with
the color palette.
* @param oppositeColor the opposite color associated with the color
palette.
* @param clashColor the clash color associated with the color
palette.
*/
ColorPalette(ColorName backgroundColorName, ColorName
textLightColorName, ColorName textDarkColorName, ColorName
contrastLightColorName, ColorName contrastMediumColorName, ColorName
contrastDarkColorName, ColorName oppositeColorName, ColorName
clashColorName) {
this.backgroundColorName = backgroundColorName;
this.textLightColorName = textLightColorName;
this.textDarkColorName = textDarkColorName;
this.contrastLightColorName = contrastLightColorName;
this.contrastMediumColorName = contrastMediumColorName;
this.contrastDarkColorName = contrastDarkColorName;
this.oppositeColorName = oppositeColorName;
this.clashColorName = clashColorName;
}
/**
* Gets the background color associated with a given ColorPalette.
*
* @return the background color associated with a given ColorPalette.
*/
public Color getBackgroundColor() { return
this.backgroundColorName.getColor(); }
/**
* Gets the light text color associated with a given ColorPalette.
*
* @return the light text color associated with a given ColorPalette.
*/
public Color getTextLightColor() { return
this.textLightColorName.getColor(); }
/* etc... */
}
==============================================================
Every single reference to ColorName in ColorPalette is flagged with a
compile error: "ColorName cannot be resolved to a variable" in the
Constants section or "ColorName cannot be resolved to a type" elsewhere.
One of the fixes is to import ColorName but when I try this, nothing
happens, even though ColorPalette and ColorName reside in the same
package and ColorName has no compile errors.
What's going on here? I can't figure out why ColorName isn't "seen" by
ColorPalette even though both are public and in the same package.
I'm trying to figure out a compiler error.
I have an enum called ColorPalette which references a second enum called
ColorName. Here is a relevant excerpt from ColorName:
==============================================================
public enum ColorName {
BLACK (new Color(0, 0, 0)),
WHITE (new Color(255, 255, 255)),
PALE_GRAY (new Color(204, 204, 204)),
PALE_DULL_RED (new Color(255, 153, 153)),
/* etc... */
MEDIUM_FADED_RED (new Color(255, 51, 51));
private final Color color;
/**
* Constructor for enum ColorName.
*
* @param color the color associated with the color name.
*/
ColorName(Color color) {
this.color = color;
}
public Color getColor() { return this.color; }
}
==============================================================
Here is an excerpt of ColorPalette which illustrates how I'm using
ColorName:
==============================================================
public enum ColorPalette {
/** Constant and data for BLUES color palette. */
BLUES (ColorName.PALE_GRAY, ColorName.WHITE, ColorName.BLACK,
ColorName.PALE_WEAK_BLUE, ColorName.PALE_DULL_BLUE,
ColorName.MEDIUM_FADED_BLUE, ColorName.PALE_DULL_ORANGE,
ColorName.RED_RED_PINK),
/** Constant and data for REDS color palette. */
REDS (ColorName.PALE_GRAY, ColorName.WHITE, ColorName.BLACK,
ColorName.PALE_DULL_RED, ColorName.MEDIUM_FADED_RED,
ColorName.DARK_FADED_RED, ColorName.PALE_DULL_TEAL,
ColorName.SPRING_SPRING_GREEN),
/* etc.... */
/** The background color associated with a given color palette. */
private final ColorName backgroundColorName;
/** The light text color associated with a given color palette. */
private final ColorName textLightColorName;
/** The dark text color associated with a given color palette. */
private final ColorName textDarkColorName;
/** The light contrast color associated with a given color palette.
*/
private final ColorName contrastLightColorName;
/** The medium contrast color associated with a given color palette.
*/
private final ColorName contrastMediumColorName;
/** The dark contrast color associated with a given color palette. */
private final ColorName contrastDarkColorName;
/** The opposite color associated with a given color palette. */
private final ColorName oppositeColorName;
/** The clash color associated with a given color palette. */
private final ColorName clashColorName;
/**
* Constructor for enum ColorPalette.
*
* @param backgroundColor the background color associated with the
color palette.
* @param textLightColor the light text color associated with the
color palette.
* @param textDarkColor the dark text color associated with the color
palette.
* @param contrastLightColor the light contrast color associated with
the color palette
* @param contrastMediumColor the medium contrast color associated
with the color palette.
* @param contrastDarkColor the dark contrast color associated with
the color palette.
* @param oppositeColor the opposite color associated with the color
palette.
* @param clashColor the clash color associated with the color
palette.
*/
ColorPalette(ColorName backgroundColorName, ColorName
textLightColorName, ColorName textDarkColorName, ColorName
contrastLightColorName, ColorName contrastMediumColorName, ColorName
contrastDarkColorName, ColorName oppositeColorName, ColorName
clashColorName) {
this.backgroundColorName = backgroundColorName;
this.textLightColorName = textLightColorName;
this.textDarkColorName = textDarkColorName;
this.contrastLightColorName = contrastLightColorName;
this.contrastMediumColorName = contrastMediumColorName;
this.contrastDarkColorName = contrastDarkColorName;
this.oppositeColorName = oppositeColorName;
this.clashColorName = clashColorName;
}
/**
* Gets the background color associated with a given ColorPalette.
*
* @return the background color associated with a given ColorPalette.
*/
public Color getBackgroundColor() { return
this.backgroundColorName.getColor(); }
/**
* Gets the light text color associated with a given ColorPalette.
*
* @return the light text color associated with a given ColorPalette.
*/
public Color getTextLightColor() { return
this.textLightColorName.getColor(); }
/* etc... */
}
==============================================================
Every single reference to ColorName in ColorPalette is flagged with a
compile error: "ColorName cannot be resolved to a variable" in the
Constants section or "ColorName cannot be resolved to a type" elsewhere.
One of the fixes is to import ColorName but when I try this, nothing
happens, even though ColorPalette and ColorName reside in the same
package and ColorName has no compile errors.
What's going on here? I can't figure out why ColorName isn't "seen" by
ColorPalette even though both are public and in the same package.