Java找不到符号枚举
我正在 Java 上对国际象棋游戏进行建模,但遇到了一些问题。代码如下(相关部分):
Enum class Couleur.java:
public enum Couleur {BLANC, NOIR}
Piece.java:
public abstract class Piece { (...) public Piece(Couleur couleurParam){ this.couleurPiece = couleurParam; } (...) }
最后是 Tour.java:
public class Tour extends Piece { (...) public Tour(Couleur couleurParam){ super(couleurParam); } (...) }
所有 .java 文件都位于同一文件夹中。然而在编译时我得到一个“找不到符号 符号:变量 NOIR location: class Plateau”
(Plateau 是实例化 Tour 的类。)
任何人都可以帮我找出这里出了什么问题吗?
非常感谢,
JDelage
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有在 Plateau 中显示无法编译的行,这并没有帮助。如果您遇到编译错误,请发布无法编译的代码。我的猜测是你正在这样做:
而不是
你可以引用枚举值而无需像这样限定它们的唯一时间是:
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:
instead of
The only times you can refer to enum values without qualifying them like this are: