[英]Android AsyncTask, warning: “Unchecked generics array creation for varargs parameter”
How do I get rid of the warning? 我如何摆脱警告? The code I'm using:
我正在使用的代码:
private void tryNew(List<Something> somethingList){
new AsyncTask<List<Something>,Void,Void>(){
@Override
protected Void doInBackground(List<Something> [] somethingList) {
//some code
return null;
}
}.execute(somethingList);
}
I was with this same warning and could remove it just by using the object I use on the parameter of the execute method, without generics. 我有同样的警告,可以通过使用我在execute方法的参数上使用的对象来删除它,没有泛型。 Sorry my bad english, but I'll try to explain better.
对不起我的英语不好,但我会尽力解释一下。
Instead create my AsyncTask this way: 而是以这种方式创建我的AsyncTask:
new AsyncTask<MyObject<GenericsInsideGenerics>, Void, Void>...
I've created this way: 我创造了这种方式:
new AsyncTask<MyObject, Void, Void>...
And it works fine! 它工作正常!
If you want to remove the warning message then you have to use the designated varargs of AsyncTask. 如果要删除警告消息,则必须使用AsyncTask的指定varargs。
private void tryNew(List<Something> somethingList){
new AsyncTask<Something,Void,Void>(){
@Override
protected Void doInBackground(Something.. s) {
//some code
return null;
}
}.execute(somethingObject1, somethingObject2, somethingObject3);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.