我的异步任务中有这个 doInBackground,并且我收到了此 Vargas 警告:
Varargs methods should only override or be overridden by other varargs methods unlike RingBankAsyncTask.doInBackground(String[]) and AsyncTask.doInBackground(String...)
protected String doInBackground(String[] urls){
String result = "";
for (int i = 0; i <= 0; i++){
result = invokePost(urls[i], this.postData);
}
return result;
}
我知道为什么会收到此警告,但是有解决方法可以消除此警告吗!?
最佳答案
改变
protected String doInBackground(String[] urls)
至
protected String doInBackground(String... urls)
varargs 表示参数的长度不同,因此尽管您在接收端像数组一样使用它,但您可以提供如下所示的参数(如果您手动调用该方法):
doInbackground(val1, val2, val3);
对比
doInbackground(new String[] { val1, val2, val3 });
通常,您可以在重写方法时始终查看父类(super class)型,以确保与它的签名匹配,以及解决许多其他有用的问题和其他问题。只需确保您已安装源即可。
关于android - 可变参数方法警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42731020/