gpt4 book ai didi

java - 返回数据类型不匹配

转载 作者:行者123 更新时间:2023-12-01 18:14:45 25 4
gpt4 key购买 nike

我在重新指定返回数据类型时遇到问题。我有FOComp实现 callabale 的类,'FOComp' 的 call() 方法返回数据类型 List<ArrayList<Mat>>如下面“FOComp”类的代码所示。

并且方法“getResults()”返回 ArrayList<Mat> 类型的数据如下面的代码所示。目前,在运行时,当我执行代码时,我收到以下错误:

该行有多个标记

  • 返回类型与 Callable<ArrayList<Mat>>.call() 不兼容
  • 返回类型与 Callable<List<Mat>>.call() 不兼容

请让我知道如何修复它。

“FOComp”类:

    static class FOComp implements Callable<List<Mat>> {//should return list contains 4 mats(0,45,90,135)

private ArrayList<Mat> gaussianMatList = null;
private List<ArrayList<Mat>> results_4OrientAngles_List = null;

public FOComp(ArrayList<Mat> gaussianMatList) {
// TODO Auto-generated constructor stub
this.gaussianMatList = gaussianMatList;
this.results_4OrientAngles_List = new ArrayList<ArrayList<Mat>>();
}
public List<ArrayList<Mat>> call() throws Exception {
// TODO Auto-generated method stub
try {
featOrient = new FeatOrientation(this.gaussianMatList);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
featOrient.start();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

this.results_4OrientAngles_List.add(featOrient.getResults());

return results_4OrientAngles_List;
}
}

'getResults':

public ArrayList<Mat> getResults() {
if (this.crossAddOrientMapsList != null) {
if (!this.crossAddOrientMapsList.isEmpty()) {

if (this.crossAddOrientMapsList.size() == 4) {
double[] theta = new double[4];

theta[0] = 0;
theta[1] = 45;
theta[2] = 90;
theta[3] = 135;

for (int i = 0; i < this.crossAddOrientMapsList.size(); i++) {
MatFactory.writeMat(FilePathUtils.newOutputPath("FinalCrossAdd_" + theta[i]+"_degs"), this.crossAddOrientMapsList.get(i));
//ImageUtils.showMat(this.crossAddOrientMapsList.get(i), "OrientMap_" + theta[i] + " degs");
}

return this.crossAddOrientMapsList;

} else {

Log.WTF(TAG, "getResults", "crossAddOrientMapsList != 4 !!");
return null;
}

} else {
Log.E(TAG, "getResults", "crossAddOrientMapsList is empty.");
return null;
}
} else {
Log.E(TAG, "getResults", "crossAddOrientMapsList is null");
return null;
}
}

最佳答案

class FOComp implements Callable<List<Mat>>

public List<ArrayList<Mat>> call()

并不真正兼容...您的call()方法应该是

@Override public List<Mat> call()

此外,最好避免在方法签名中使用实现类,而是使用接口(interface)(在本例中,使用 List 而不是 ArrayList)。这也将解决您的“多个标记”之一的问题:-)

干杯,

关于java - 返回数据类型不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30343892/

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