Enums 在处理2.2.1的枚举中,此令牌后面应为令牌“{”,应为@

Enums 在处理2.2.1的枚举中,此令牌后面应为令牌“{”,应为@,enums,syntax-error,processing,Enums,Syntax Error,Processing,我用processing 2.2.1制作了一个项目,我使用了一个enum。然而,我调用了我的enum color.java,我遇到了一个错误: 令牌{上的语法错误,应在该令牌之后 这是我的密码: public enum Colour { // --> on this line RED({0xFF0000, 0xDD0000, 0x990000, 0x660000, 0x330000}), GREEN({0x00FF00, 0x00DD00, 0x009900, 0x00

我用processing 2.2.1制作了一个项目,我使用了一个enum。然而,我调用了我的enum color.java,我遇到了一个错误:

令牌{上的语法错误,应在该令牌之后

这是我的密码:

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[]开头:

只有在声明变量或字段的同时初始化变量或字段时,才可以忽略此项:

int[] ints = { 1, 2, 3 };

在此之后,您需要将构造函数的可见性从public降低到package private或private,然后一切都会正常工作。

创建新int数组的语法需要从new int[]开始:

只有在声明变量或字段的同时初始化变量或字段时,才可以忽略此项:

int[] ints = { 1, 2, 3 };
在这之后,您需要将构造函数的可见性从public降低到package private或private,然后事情就可以进行了。

您可以使用varargs

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;
    }
}
您可以使用varargs

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;
    }
}