0

有一个方法 protected Long doInBackground(URL... urls) {}。URL... urls 是什么意思?

 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile(urls[i]);
             publishProgress((int) ((i / (float) count) * 100));
             // Escape early if cancel() is called
             if (isCancelled()) break;
         }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }

这些来自http://developer.android.com/reference/android/os/AsyncTask.html

4

1 回答 1

1

“type ... name”语法是用于可变长度参数列表的 Java。这意味着零个或多个 URL 值。它们通过将 urls(在这种情况下)视为方法中的数组(URL[] urls)来引用。对于 AsyncTask,您将在 .execute() 方法中传递一个或多个 URL:.execute(url1, url2, url3)。

于 2013-05-18T03:39:32.733 回答