Java 多参数点表示法 - Varargs [英] Java multiple arguments dot notation - Varargs

查看:27
本文介绍了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[].此处记录了可变参数.它们是在 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.

这篇关于Java 多参数点表示法 - Varargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆