简体   繁体   中英

Very odd compilation error with varargs

I am writing an enum for all the opcodes in the JVM. It isn't complete, and looks like this so far:

public enum Opcode {
    NOP(),
    ACONST_NULL(),
    ICONST_M1(),
    ICONST_0(),
    ICONST_1(),
    // a zillion more of these
    JSR_W();

    private Opcode(Class<? extends Argument> args...) {
    }
}

There is a compilation error on the line of the construction declaration:

')' expected

What is going on?

The ... notation goes on the parameter type not on the parameter name, like so

private Opcode(Class<? extends Argument>... args) {
}

For thoroughness, the Java Language Specification states that a method's parameter list has the following form

FormalParameterList:
    LastFormalParameter
    FormalParameters , LastFormalParameter

where LastFormatParameter has the form

LastFormalParameter:
    VariableModifiersopt Type... VariableDeclaratorId
    FormalParameter

The ... comes after the parameter type declaration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM