以下方法中的3个点是什么意思?
public void myMethod(String... strings){
// method body
}
Run Code Online (Sandbox Code Playgroud) 我希望能够创建一个像这样的函数:
class A {
private String extraVar;
public String myFormat(String format, Object ... args){
return String.format(format, extraVar, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是在方法中args处理,因此是单个参数,而我希望每个in 都作为新参数传递.既然也是一个带有变量参数的方法,这应该是可能的.Object[]myFormatString.formatObjectargsString.format
如果这是不可能的,有没有像这样的方法String.format(String format, Object[] args)?在这种情况下,我可以在前面加上extraVar到args使用新的数组,并把它传递给该方法.
我在Android文档中阅读有关AsyncTask的内容.
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");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是doInBackground(URL... urls) …
可能重复:
此方法签名的省略号是什么?
例如: protected void onProgressUpdate(Context... values)
可能重复:
Java,参数中有3个点
public static void getImages(String... folders) throws IOException{
}
Run Code Online (Sandbox Code Playgroud)
在上述getImages()方法中,为什么有三个点.这是什么意思?我搜索谷歌但找不到任何东西.