我如何得到Vector <type> Arraylist <type>作为call()的返回?

Jus*_*ing 1 java android asynchronous callable

如何使以下Java代码工作:

public class Worker implements Callable<myObject>{

   @Override
   public ArrayList<myObject> call() throws Exception {
      ArrayList<myObject> lst_MyObjects= new ArrayList<myObject>();     
      return lst_MyObjects;
   }
}
Run Code Online (Sandbox Code Playgroud)

错误:返回类型与Callable.call()不兼容

我只想返回一个特定类型的容器(Vector<>/ ArrayList<>等)

Sud*_*hul 7

只要用这个:

public class Worker implements Callable<List<myObject>>{
Run Code Online (Sandbox Code Playgroud)

通过使用List,您可以返回a ArrayList或a Vector,但建议使用ArrayList而不是a Vector.