java string args_java – 语法“final String … args”是什么意思/做什么?
Java中參數(shù)的省略號(hào)表示類(lèi)型的vararg.因此,在您的情況下,…意味著您可以將任意數(shù)量的String參數(shù)傳遞給doInBackground方法.
因此,您可以調(diào)用此方法doInBackground(“String1”,“String2”,“String3”)或doInBackground(“String1”)或doInBackground(“String1”,“String3”,“String4”)或任何其他形式.
The three periods after the final parameter’s type indicate that the final argument may be passed as an array or as a sequence of arguments. Varargs can be used only in the final argument position. Given the new varargs declaration for MessageFormat.format,the above invocation may be replaced by the following shorter and sweeter invocation
最后有它的通常含義.順便說(shuō)一句,這個(gè)功能在Java5或更新版本中可用.
正如以上兩個(gè)鏈接所提到的,它只不過(guò)是含糖的數(shù)組.基本上,當(dāng)你定義myMethod(T … vararg)時(shí),Java會(huì)將其視為myMethod(T [] vararg).當(dāng)你調(diào)用myObj.myMethod(t1,t2,t3,…,tn)時(shí),Java將它傳遞給myObj.myMethod(new T [] {t1,tn}).
總結(jié)
以上是生活随笔為你收集整理的java string args_java – 语法“final String … args”是什么意思/做什么?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python制作系统程序与html交互_
- 下一篇: 小黄蜂手机怎么样(大黄蜂手机是什么牌子)