1

Is it possible to have an array as an attribute in an enum?

public enum dsfd{
    MANEUVERS({"IMC_ID_MAN_TYPE"});

    public final String columns[];
    private dsfd(String column[]){
        this.columns = column;
    }
}

I get the errors:

Syntax error on token "{", @ expected after this token      line 1 
Syntax error, insert "Identifier" to complete EnumConstant  line 2

What am I doing wrong?

I don't know how to unflag as duplicate but my question was not how to initialize an array with values but how to do it directly in the enumeration constructor (or any other method call I guess...).

kotoko
  • 599
  • 2
  • 6
  • 22

2 Answers2

2

You aren't initializing your array correctly - you're missing a call to new:

MANEUVERS(new String[]{"IMC_ID_MAN_TYPE"});
Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

Your code should be corrected like the following

public enum dsfd{
    MANEUVERS(new String[]{"IMC_ID_MAN_TYPE"});

    public final String columns[];
    private dsfd(String column[]){
        this.columns = column;
    }
}
Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
hetptis
  • 786
  • 1
  • 12
  • 23