Java中的枚举语法用法

时间:2014-01-04 16:47:29

标签: java enums

现在我正在尝试用java制作玩具TicTacToe程序。

public class Board {
private enum Slot {
    UNFILLED, FIRSTPLAYER, SECONDPLAYER
}

private Slot[][] board = {{"UNFILLED", "UNFILLED", "UNFILLED"}, {"UNFILLED", "UNFILLED", "UNFILLED"}, {"UNFILLED", "UNFILLED", "UNFILLED"}};

我声明了一个名为Slot的枚举,我正试图用这个枚举填充我的主板。这样做的正确语法是什么?

1 个答案:

答案 0 :(得分:3)

您可以使用:

private Slot[][] board = {{Slot.UNFILLED, ...

private Slot[][] board = {{UNFILLED, ...

在这种情况下,您需要添加静态导入:import static your.package.Board.Slot.*;