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;
    }
}
2
  • I realized that, after I had answered this question, I had answered it before. Sorry about that. Commented Jan 15, 2015 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 Commented Jan 16, 2015 at 14:05

1 Answer 1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.