1

My classes are as follows

public interface A {
    public void doSomething();
}
public abstract class B implements A {
    public void doOneMoreThing() {
        // 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

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
Nayn
  • 3,594
  • 8
  • 38
  • 48

2 Answers2

5

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

Community
  • 1
  • 1
mdma
  • 56,943
  • 12
  • 94
  • 128
  • Precise. I was using 1.5 Thanks. – Nayn Jun 01 '10 at 13:30
  • Actually, setting source and target to 1.5 won't produce this error. Nor will the latest update release of JDK 1.5. Only older versions of JDK 1.5. – Kevin Bourrillion Jun 02 '10 at 00:16
  • Plus, if `-source 1.6 -target 1.6` worked, that would mean he's on JDK 1.6 or later, in which case there would be no reason to specify those arguments, would there? – Kevin Bourrillion Jun 02 '10 at 00:17
  • @Kevin Bourrillion - I use JDK 6 and often have projects inadvertently set to -source/-target 1.5. (E.g. when importing a maven project into IDEA - my common parent pom defines source to be 1.5.) So, this would be the fix in such a case. I wasn't considering that he was actually using JDK 1.5, and that's not the intent of my post. I think your downvote is harsh considering the the answer solved the OP's problem, and that the answer is valid in the typical case of using 1.6. – mdma Jun 02 '10 at 00:31
  • I know there are differing philosophies about downvotes. I tend to believe the concept is more useful when we're not afraid to use it on answers that just aren't very good/useful (as opposed to that the answer has to be BAD). However, your new edit is a lot better, so good-bye downvote. – Kevin Bourrillion Jun 03 '10 at 00:30
2

you should use

@Override

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

RoflcoptrException
  • 51,941
  • 35
  • 152
  • 200