返回数据类型不匹配

时间:2015-05-20 08:11:27

标签: java multithreading callable countdownlatch

我正面临一个问题,即重新指定返回数据类型。我有实现callabale的FOComp类,'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;
    }
}

2 个答案:

答案 0 :(得分:3)

class FOComp implements Callable<List<Mat>>

public List<ArrayList<Mat>> call()

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

@Override public List<Mat> call()

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

干杯,

答案 1 :(得分:1)

您的类声明表示您将返回Mat的列表(FOComp implements Callable<List<Mat>>),但您的call方法签名表示您将返回Mat的ArrayList列表({{1 }})。

您需要使它们保持一致。