Intro
My real question is about the use of the annotation. Trying to find an answer myself, I ran into several other questions. This is why there are also related questions below. I hope this is not too confusing.
Question
Should a method that implements an interface method be annotated with @Override
? Eclipse for instance automatically inserts an @Override
annotation after using the Quick Fix option 'Add unimplemented methods'. Is this correct behavior?
The javadoc of the Override
annotation says:
Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.
I don't think that an interface is technically a superclass. Or is it? Compilers don't generate an error at least when the annotation is used in this case.
Eclipse can give warnings if you omit this annotation for overriding ''real'' superclass methods. It doesn't if you omit it for interface methods. Another question revealed that this is a glitch in Eclipse.
The reason this worries me a little bit, is that I try to be consistent. But if the IDE doesn't give warnings when the annotation is not there and automatically generates them on the other hand, consistency is rather difficult.
Edit: Two articles with relevant info: @Override and @Override Snafu