Search code examples
javamultithreadingcallablecountdownlatch

Mismatch of return datatype


i am facing a problem regrading specifying the return data type. I have the FOComp class which implements callabale, the call() method of the 'FOComp' returns data type List<ArrayList<Mat>> as shown in the code of 'FOComp' class below.

and the method 'getResults()' returns data of type ArrayList<Mat> as shown in the code below. and currently, at run time, when I execute the code, I receive the folowing error:

Multiple markers at this line

  • The return type is incompatible with Callable<ArrayList<Mat>>.call()
  • The return type is incompatible with Callable<List<Mat>>.call()

kindly please let me know how to fix it.

'FOComp' class:

    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;
    }
}

Solution

  • class FOComp implements Callable<List<Mat>>
    

    and

    public List<ArrayList<Mat>> call()
    

    aren't really compatible... Your call() method should be

    @Override public List<Mat> call()
    

    Also, it is good practice to avoid implementation classes in method signatures, use the interfaces instead (in this case, use List rather than ArrayList). That will also fix your problem with one of the "multiple markers" :-)

    Cheers,