代码已经写好了,所以我是borrowing it from here并将其调整到我的代码中.我遇到过这一小段代码:
private class ExportDatabaseFileTask extends AsyncTask<String,Void,Boolean> { private final ProgressDialog dialog = new ProgressDialog(ManageData.this); // can use UI thread here protected void onPreExecute() { this.dialog.setMessage("Exporting database..."); this.dialog.show(); } // automatically done on worker thread (separate from UI thread) protected Boolean doInBackground(final String... args) {
我以前从未见过参数String … args.这是什么意思/做什么?
谢谢!
Moscro
解决方法
因此,您可以调用此方法doInBackground(“String1”,“String2”,“String3”)或doInBackground(“String1”)或doInBackground(“String1”,“String3”,“String4”)或任何其他形式.
见这里http://download.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
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或更新版本中可用.
参见:http://www.developer.com/java/other/article.php/3323661
正如以上两个链接所提到的,它只不过是含糖的数组.基本上,当你定义myMethod(T … vararg)时,Java会将其视为myMethod(T [] vararg).当你调用myObj.myMethod(t1,t2,t3,…,tn)时,Java将它传递给myObj.myMethod(new T [] {t1,tn}).