Java多参数点符号 - Varargs

问题描述:

我刚刚承认带有多个参数的方法声明的点符号

像这样:

I've just acknowledged dot notation for method declaration with multiple arguments
like this:

public function getURLs(URL... urls){
    for(int i = 0; i < urls.length; i++){
        // walk through array of arguments
    }
}

并且像这样使用

getURLs(url1, url2, url3);

其中这些方法参数被隐式转换为 URL [] urls

where those method arguments are converted implicitly into URL[] urls


  1. 我是否理解其行为?

  2. 此语法的文档在何处?

  3. 支持哪个版本的JRE(J2ME,J2SE,Dalvik)?


是的,这就是它的工作原理。参数自动放入数组中。参数urls的行为类似于 URL [] 此处记录了Varargs 。它们是在Java 1.5中引入的,因此可以在J2SE 1.5+和所有Android中使用,因为它支持Java 1.5+语言功能。没有JavaME / J2ME版本支持它。

Yes, that is how it works. The arguments are automatically put into an array. The argument "urls" behaves like a URL[]. Varargs are documented here. They were introduced in Java 1.5, so, are available in J2SE 1.5+, and all of Android since it supports Java 1.5+ language features. No version of JavaME/J2ME supports it.