简体   繁体   English

varargs非常奇怪的编译错误

[英]Very odd compilation error with varargs

I am writing an enum for all the opcodes in the JVM. 我正在为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 为了详尽起见, Java语言规范声明方法的参数列表具有以下形式

FormalParameterList:
    LastFormalParameter
    FormalParameters , LastFormalParameter

where LastFormatParameter has the form 其中LastFormatParameter具有以下形式

LastFormalParameter:
    VariableModifiersopt Type... VariableDeclaratorId
    FormalParameter

The ... comes after the parameter type declaration. ...在参数类型声明之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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