문제

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; }
        };
    }
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top