Here I am, thinking I know Java, and I get the error Variable 'storage' might not have been initialized. Here is my code:
public class RobbleSet {
private final Set<Robble> storage; // Error occurs here
public RobbleSet() {
storage = new HashSet<Robble>();
}
public addRobble(Robble r) {
storage.add(r); // Error occurs here too
}
}
storage is initialized in the constructor. What gives?
One problem is that you’re not declaring a return type for
addRobble; you need to change this:to this:
I suspect that this is the problem — that your compiler thinks that
addRobbleis a misnamed constructor, so is complaining that it fails to initializestorage— but even if it turns out that it’s not the problem, it’s definitely a problem.