views:

89

answers:

1

Hi,

I'm modeling a chess game on Java, and I'm having some problem. Here's what the code looks like (the relevant parts):

Enum class Couleur.java:

public enum Couleur {BLANC, NOIR}

Piece.java:

public abstract class Piece {
(...)
  public Piece(Couleur couleurParam){
    this.couleurPiece = couleurParam;
  }
(...)
}

And finally Tour.java:

public class Tour extends Piece {
(...)
  public Tour(Couleur couleurParam){
    super(couleurParam);
  }
(...)
}

All the .java files are in the same folder. Yet at compile I get a "cannot find symbol symbol : variable NOIR location: class Plateau"

(Plateau is the class that instantiates Tour.)

Can anyone help me figure out what's wrong here?

Many thanks,

JDelage

+2  A: 

It doesn't help that you've not shown the line in Plateau that fails to compile. If you're getting compilation errors, please post the bit of code which doesn't compile. My guess is you're doing this:

new Tour(NOIR)

instead of

new Tour(Couleur.NOIR)

The only times you can refer to enum values without qualifying them like this are:

  • Within the enum itself
  • Using a static import
  • In a switch statement
Jon Skeet
Jon - thanks, that's it. First time I use enum, rookie mistake.I feel I know a celebrity now that one of my question has been answered by Jon Skeet. Maybe there should be a badge for that, too. :-)
JDelage