Another Compiler Error

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.
 
N

Novice

Please ignore this thread. The problem was simply that Eclipse got confused
for some reason. Rebuilding the project eliminated the problem.
Sorry if I wasted anyone's time.
 
R

Roedy Green

Can an enum make references to another enum?
Sure, but normally you use an EnumSet to create sets of enums.

See http://mindprod.com/jgloss/enumset.html

http://mindprod.com/jgloss/enum.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
It's difficult to be rigorous about whether a machine really knows,
thinks, etc., because we’re hard put to define these things.
We understand human mental processes only slightly better than
a fish understands swimming.
~ John McCarthy (born: 1927-09-04 died: 2011-10-23 at age: 84).
Inventor of the term AI (Artificial Intelligence),
the short-circuit OR operator (|| in Java),
and LISP (LIst Processing Language) that makes EMACS
(Extensible MACro System) so addictive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top