Java int...数组表示法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/580743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 12:56:22  来源:igfitidea点击:

Java int... array notation

javaarrays

提问by jtgameover

I've seen this before in a method parameter, and it appears to allow an arbitrary number of parameters to be stuffed in an array created at run-time. What's the official name of this language feature? Thanks!

我以前在方法参数中看到过这种情况,它似乎允许将任意数量的参数填充到运行时创建的数组中。此语言功能的正式名称是什么?谢谢!

    public static void trace(View view, RecyclerTraceType type, int... parameters) {

    RecyclerTrace trace = new RecyclerTrace();
    trace.position = parameters[0];
    trace.indexOnScreen = parameters[1];
}

回答by amit

You are seeing the Java 1.5 varargsfeature. Under the hoods its just an array with syntactic sugaring.

您看到的是 Java 1.5 varargs功能。在引擎盖下,它只是一个带有语法糖的数组。