1

I am creating an enigma simulation program for some practice with enums. The following is a preliminary draft for the enum of a machine, so I don't have any of the specifics, yet.

The issue is that my IDE keeps saying that the curly braces are not supposed to be there, at the point I am trying to pass an array into the enum constructor.

Is there something wrong with my enum constructor or the enum constant declaration? How can I correct this to make it work?

public enum MACHINETYPE {
    WehrmachtEnigma (4, {true, true, true, false}),
    KriegsmarineM4(4, {true, true, true, true}),
    Abwehr(4, {true, true, true, true});

    private final int ROTORS_COUNT;
    private final boolean[] STEPPING;

    private MACHINETYPE(int rotors, boolean[] stepping){
        ROTORS_COUNT = rotors;
        STEPPING = stepping;
    }
}
Andy Brown
  • 18,961
  • 3
  • 52
  • 62
AlterionX
  • 81
  • 1
  • 10
  • I realized that, after I had answered this question, I had answered it *before*. Sorry about that. – Makoto Jan 15 '15 at 17:30
  • This question is not just about array initialisation but about passing arrays as arguments. It doesn't look like a true duplicate of [Array initialisation in java](http://stackoverflow.com/questions/16139977/array-initialisation-in-java) – Andy Brown Jan 16 '15 at 14:05

1 Answers1

1

You are not declaring your arrays properly. They should be declared using new boolean[] { ... }. However as your arrays are arguments to a constructor you could shorten your declarations by using a varargs notation. This will remove your error message.

enum MACHINETYPE{
    WehrmachtEnigma (4, true, true, true, false),
    KriegsmarineM4(4, true, true, true, true),
    Abwehr(4, true, true, true, true);

    private final int ROTORS_COUNT;
    private final boolean[] STEPPING;

    private MACHINETYPE(int rotors, boolean... stepping){
        ROTORS_COUNT = rotors;
        STEPPING = stepping;
    }
}
Andy Brown
  • 18,961
  • 3
  • 52
  • 62