Atom Feed SITE FEED   ADD TO GOOGLE READER

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.
I agree modifiers should be @Final @Static and so on, so inline sounds logical.
My issue is that the meta-annotation concept is rarely used in frameworks except for Guice or WebBeans. So with JPA, EJB3 and so on, you end up with 4 to 5 annotations with parameters on members and more than 10 for classes.
Inlining them is impossible.
So, when meta annotations will be widespread we should inline, in the meantime I compromised on "Above".
@Override
public String
toString() {
return "Delivery " + id;
}