Alex Rivera | Logout

Should I add an @Override annotation when implementing abstract methods in Java?

Asked 2009-06-17T08:52:07.800
62

When overriding a non-virtual method in Java, use of the @Override annotation is recommended, but what if I implement an abstract method? Should I use @Override then as well?

Edit
Report

2 Answers

18

Yes. It is recommended practise by Joshua Bloch in Effective Java.

answered 2009-06-17T08:56:26.343
10

Actually, Joshua Bloch, in the final paragraph of page 178 in Effective Java (2nd Ed.), says that it's not essential for methods of concrete classes that override abstract methods to use the Override annotation because the compiler would give an error anyway. However, "it is not harmful to do so".

I'd recommend choosing a strategy and sticking with it consistently.

answered 2010-01-05T10:32:21.710

Your Answer