Question

The class in question is this. As you can see, it's very simple. Just to learn about the workings of anonymous inner classes. In this case I am getting 4 errors saying that the symbols WaterLevel and ChlorineLevel cannot be found. Can you see what is wrong with this?

public class Pool {
    public WaterLevel level() {
        return new WaterLevel() {
            private String level = "empty";
            public String litresToFull() { return "3000"; }
        };
    }

    public ChlorineLevel chlorine(final int amt){
        return new ChlorineLevel() {
            private int level = amt;
            int addChlorine() { level += amt; return level; }
        };
    }
}
Était-ce utile?

La solution

Rohit Jain said

True, but those anonymous inner classes are actually subclass of WaterLevel and ChlorineLevel respectively. You've to have those classes.

This lead to me to realize that I have to define an interface for each anonymous inner class that I'm using. Just wanted to post this so that it's obvious this is solved.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top