Search code examples
javaannotationsinitializationblockscjp

Annotations on an initialization block???? static or not


I was just coding a Stripes action bean, starting with an annotated method.

By mistake i wrote:

@After(stages = LifecycleStage.ActionBeanResolution) {
    // code here
}

The compiler is OK

So it seems we can put annotations on static and nonstatic init blocks

@After(stages = LifecycleStage.ActionBeanResolution) 
{
    // code here
}

@After(stages = LifecycleStage.ActionBeanResolution) 
static {
    // code here
}

Do you have any usecase idea of such a strange thing?


Solution

  • Sorry it's a problem in my ide, it doesn't compile