开发者

@Override causes issues with class hierarchy involving interface, abstract class and concrete class

My classes are as follows

public interface A {
    public void doSomething();
}
public abstract class B implements A {
    public void doO开发者_如何学GoneMoreThing() {
        // Do one more thing
    }
}
public class C extends B {
    @Override                <---- Causes error
    public void doSomething() {
        // Do something
    }
}

Could somebody tell me, why this @Override annotation is causing error?

Thanks Nayn


Check that you are using JDK 1.6 and that your -source and -target parameters (if defined) set to 1.6. The semantics of @Override changed in Java 6. In Java 5, @Override was not allowed to override interface methods (only superclass methods), but it is allowed in Java 6 (and recent versions of JDK 5, from u21 onwards)

See Why is javac failing on @Override annotation


you should use

@Override

You wrote @Overrides and then it doesn't work anymore ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜