Pergunta

I receny found out that packages are annotable in Java too. So I really wondered how that would work. Especially how the syntax would work. And that's what i've found out:

 @SomeAnnotation(some="values")
 package x.y;
 class Example {

 }

So I annotated the package x.y with @SomeAnnotation.

Now my question: Do I have to write this annotation over the package declarations in ALL members of this package? And if not, is it possible to put a different annotation to the package in another class?

Foi útil?

Solução

No you don't have to... If you had to there's no point in having package annotations. (they will be the same as class level annotations)

No it's not possible to quote the JLS

Annotations may be used on package declarations, with the restriction that at most one annotated package declaration is permitted for a given package.

JLS 7.4.1.1

Outras dicas

The best place to annotate a package is package-info.java file. See JLS 7.4.1

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top