Anal Retentive Java Style - Annotation Placement
A shared codebase means a shared styleguide. An issue that's come up a lot recently is where to put the damn@Override
tag, and similar marker annotations. Above:
@Override
public String toString() {
return "Delivery " + id;
}
Inline
@Override public String toString() {
return "Delivery " + id;
}
Here's my claim for writing the annotation inline.
@Override
isn't much different from final
. They each constrain the method's inheritance - that it must override, or that it mustn't be overridden. Since final
was thought up when the Java language was being designed, it gets to be a language feature - whereas @Override
is an extension. If the Java language were to be designed again, final
would probably be @Final
.More practically, I don't think
@Override
is more important than the other modifiers. On it's own line, it's almost like the annotation is somehow more important than say, the method name, which has to share its space with the other modifiers.So put
@Override
beside public
. It's just another modifier.