什么是"弦乐..."在java中? [英] What is "String..." in java?
问题描述
可能重复:结果
可变参数和'…参数结果
Java,第3点中的参数
我看到在我的Android的Java文件这个定义。
它看起来就像的String []。难道他们有什么不同?
谢谢。
I saw this definition in my android java file. It looks just like String[]. Are they different? Thank you.
推荐答案
varags
。如果一个方法签名办法(参数参数,字符串... X)
将需要有一个参数
类型的对象和任何 String对象的数量。
varags
. If a method signature is method(Param param, String... x)
it will take one Param
type of object and any number of String objects.
有几个,如果它很酷的事情:
There are couple if cool things about it:
-
这没什么特别的。这只是加糖阵列。因此,
方法(为MyObject ... O)
是一样的方法(为MyObject [] O)
。
VARARG的必须的参数列表中的最后一个参数。
Vararg has to be the last parameter in argument list.
有是咬了我这一次有趣的事情。 方法(为MyObject ... O)
可称为()方法
没有任何编译错误。 Java将在内部转换无参数调用办法(新MyObject的[0])
。因此,应注意这一点。
There is this funny thing that bit me once. method(MyObject... o)
can be called as method()
without any compilation error. Java will internally convert the no-arg call to method(new MyObject[0])
. So, be aware of this.
这篇关于什么是"弦乐..."在java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!