Token "{", @ expected after this token in enum for processing 2.2.1
Token "{", @ expected after this token in enum for processing 2.2.1
我用 processing 2.2.1 做了一个项目,我使用了一个枚举。但是我调用了我的枚举 Colour.java,但出现错误:
Syntax error on token "{", @ expected after this token.
这是我的代码:
public enum Colour
{ // --> on this line
RED({0xFF0000, 0xDD0000, 0x990000, 0x660000, 0x330000}),
GREEN({0x00FF00, 0x00DD00, 0x009900, 0x006600, 0x003300}),
BLUE({0x0000FF, 0x0000DD, 0x000099, 0x000066, 0x000033});
private final int[] shades;
public Colour(int[] shades)
{
this.shades = shades;
}
public int[] getShades()
{
return shades;
}
}
创建新 int 数组的语法需要以 new int[]
:
开头
RED(new int[] {0xFF0000, 0xDD0000, 0x990000, 0x660000, 0x330000}),
// ^^^^^^^^^
唯一 可以省略的时间是在声明变量或字段的同时初始化它:
int[] ints = { 1, 2, 3 };
之后,您需要将构造函数的可见性从 public 降低为 package-private 或 private,然后一切正常。
您可以使用可变参数
public enum Colour
{ // --> on this line
RED(0xFF0000, 0xDD0000, 0x990000, 0x660000, 0x330000),
GREEN(0x00FF00, 0x00DD00, 0x009900, 0x006600, 0x003300),
BLUE(0x0000FF, 0x0000DD, 0x000099, 0x000066, 0x000033);
private final int[] shades;
Colour(int... shades)
{
this.shades = shades;
}
public int[] getShades()
{
return shades;
}
}
我用 processing 2.2.1 做了一个项目,我使用了一个枚举。但是我调用了我的枚举 Colour.java,但出现错误:
Syntax error on token "{", @ expected after this token.
这是我的代码:
public enum Colour
{ // --> on this line
RED({0xFF0000, 0xDD0000, 0x990000, 0x660000, 0x330000}),
GREEN({0x00FF00, 0x00DD00, 0x009900, 0x006600, 0x003300}),
BLUE({0x0000FF, 0x0000DD, 0x000099, 0x000066, 0x000033});
private final int[] shades;
public Colour(int[] shades)
{
this.shades = shades;
}
public int[] getShades()
{
return shades;
}
}
创建新 int 数组的语法需要以 new int[]
:
RED(new int[] {0xFF0000, 0xDD0000, 0x990000, 0x660000, 0x330000}),
// ^^^^^^^^^
唯一 可以省略的时间是在声明变量或字段的同时初始化它:
int[] ints = { 1, 2, 3 };
之后,您需要将构造函数的可见性从 public 降低为 package-private 或 private,然后一切正常。
您可以使用可变参数
public enum Colour
{ // --> on this line
RED(0xFF0000, 0xDD0000, 0x990000, 0x660000, 0x330000),
GREEN(0x00FF00, 0x00DD00, 0x009900, 0x006600, 0x003300),
BLUE(0x0000FF, 0x0000DD, 0x000099, 0x000066, 0x000033);
private final int[] shades;
Colour(int... shades)
{
this.shades = shades;
}
public int[] getShades()
{
return shades;
}
}