[Jsr308-statements] annotations on code blocks

Trevor Harmon trevor at vocaro.com
Sat Feb 3 01:50:41 EST 2007


On Feb 2, 2007, at 7:21 PM, Eugene Kuleshov wrote:

> Here are a few examples of the possible syntax. It is been  
> suggested that prefix form is more readable then postfix variant.  
> Anyways we have the following variants to consider:
>
> @ReadOnly for(...) { ... }
> for(...) @ReadOnly { ... }
> for(...) { ... } @ReadOnly

I agree that prefix form is more readable, but there is another  
argument for prefix: consistency. Annotations on methods, for  
instance, are written like this:

@Test void foo() { }

Not like this:

void foo() @Test { }

Nor like this:

void foo() { } @Test

Annotations on other constructs should follow this same pattern.

>  Using prefix form annotations could look like this:
>
> // static code block, method body or inner code block
> @ReadOnly { ... }
> @ReadOnly synchronized(...) { ... }
>
> @ReadOnly for(...) { ... }
>
> @ReadOnly if() { ... }
> @ReadOnly else { ... }
>
> @ReadOnly try { ... }
> @ReadOnly catch()  { ... }
> @ReadOnly finally { ... }

That all looks fine to me.

Trevor




More information about the Jsr308-statements mailing list