我用谷歌搜索了我的问题,但没有找到与我的情况相匹配的相关示例。
public class Game{
static enum Tile
{
static //Syntax error, insert "Identifier" to complete EnumConstantHeader
{
DIRT = new Tile("DIRT", 1); //Cannot instantiate the type Game.Tile
GRASS = new Tile("GRASS", 2);
ROCK = new Tile("ROCK", 3);
EXIT = new Tile("EXIT", 4);
PLAYER = new Tile("PLAYER", 5);
PLAYER_LEFT = new Tile("PLAYER_LEFT", 6);
PLAYER_RIGHT = new Tile("PLAYER_RIGHT", 7);
//For all above declared fields, I am getting this compile time errors :
/*
Multiple markers at this line
- Cannot instantiate the type
Game.Tile
- DIRT cannot be resolved to a
variable
*/
Tile[] arrayOfTile = new Tile[8];
arrayOfTile[0] = EMPTY;
arrayOfTile[1] = DIRT;
arrayOfTile[2] = GRASS;
arrayOfTile[3] = ROCK;
arrayOfTile[4] = EXIT;
arrayOfTile[5] = PLAYER;
arrayOfTile[6] = PLAYER_LEFT;
arrayOfTile[7] = PLAYER_RIGHT;
$VALUES = arrayOfTile;
}
}
}
在我的例子中,我已经声明了上面描述的枚举。但是我收到了很多编译错误,我在上面的代码中作为注释插入了这些错误。有人可以指出我正确的方向来解决这个问题吗?