java string args_java – 语法“final String … args”是什么意思/做什么?
Java中參數的省略號表示類型的vararg.因此,在您的情況下,…意味著您可以將任意數量的String參數傳遞給doInBackground方法.
因此,您可以調用此方法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
最后有它的通常含義.順便說一句,這個功能在Java5或更新版本中可用.
正如以上兩個鏈接所提到的,它只不過是含糖的數組.基本上,當你定義myMethod(T … vararg)時,Java會將其視為myMethod(T [] vararg).當你調用myObj.myMethod(t1,t2,t3,…,tn)時,Java將它傳遞給myObj.myMethod(new T [] {t1,tn}).
總結
以上是生活随笔為你收集整理的java string args_java – 语法“final String … args”是什么意思/做什么?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python制作系统程序与html交互_
- 下一篇: java中$和 的区别详解_Mybati