什么是"弦乐..."在java中? [英] What is "String..." in java?

查看:212
本文介绍了什么是"弦乐..."在java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  可变参数和'…参数结果
   Java,第3点中的参数

我看到在我的Andr​​oid的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:


  1. 这没什么特别的。这只是加糖阵列。因此,方法(为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屋!

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