gpt4 book ai didi

java - 我如何获得 Vector Arraylist 作为 call() 的返回值?

转载 作者:行者123 更新时间:2023-11-29 09:48:50 26 4
gpt4 key购买 nike

如何让下面的 Java 代码工作:

public class Worker implements Callable<myObject>{

@Override
public ArrayList<myObject> call() throws Exception {
ArrayList<myObject> lst_MyObjects= new ArrayList<myObject>();
return lst_MyObjects;
}
}

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

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

最佳答案

只需使用这个:

public class Worker implements Callable<List<myObject>>{

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

关于java - 我如何获得 Vector<type> Arraylist<type> 作为 call() 的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16395974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com