The blank final field seed may not have been initialized

aConfusedProgrammer :

So I'm trying to set a default memory size and create an array of heuristics, but I keep getting the error "The blank final field seed may not have been initialised". The aoHeuristics is an array of Heuristics. I'm not sure what I'm doing wrong...

public class zoo_Problem extends ProblemDomain implements Visualisable {

    private final long seed;

    public int defaultSize;

    private HeuristicInterface[] aoHeuristics;

    public zoo_Problem(long seed, int defaultSize) {

         super(seed);

         this.defaultSize = 5;

         int[][] aoHeuristics = { { 0, 1, 2 }, { 3, 4 }, { 5, 6 } };
    }

}
Tom Hawtin - tackline :

Initialise the final field. Add this line to the constructor:

     this.seed = seed;

Given the you are passing seed to the superclass constructor, you may wish to remove the field instead.

As for aoHeuristics, you will need to create new objects of the appropriate type for each element in the array, as well as creating the array and assigning it to the field.

The language does not require the field aoHeuristics to be assigned as it is not final - it'll just be null and you'll get a NullPointerException whenever you try to dereference it.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=378759&siteId=1