This site requires JavaScript, please enable it in your browser!
Greenfoot back
cobarr
cobarr wrote ...

2014/5/26

Enums Error Message

cobarr cobarr

2014/5/26

#
public enum Op {
        ADD("+"),

        SUBTRACT("-");

        private final String mnemonic;
        private final int level;

        public String mnemonic() {
            return this.mnemonic;
        }

        public int level() {
            return this.level;
        }
    }
The Error message highlights ("+") and says: Constructor Op in enum Question.Op cannot be applied to given types. I can't seem to understand the error message and what I can do to fix this.
cobarr cobarr

2014/5/26

#
Hi! Sorry, I figured it out! :)
danpost danpost

2014/5/26

#
cobarr wrote...
Hi! Sorry, I figured it out! :)
How did you fix it (for others). I was about to post this:
I believe you still need an Op constructor within the enum definition block:
Op(String mnemonic) {
    this.mnemonic = mnemonic;
}
The error was probably you trying to create an Op instance using a string argument; but there was no constructor with that form. Hence, 'given types could no be applied'.
Was I right?
You need to login to post a reply.