views:

179

answers:

2

I understand the purpose of class annotations: http://stackoverflow.com/questions/1372876/how-and-where-are-annotations-used-in-java. But what is the purpose of package annotations, as described here and here?

Why would you want to associate meta-data with a package? What kinds of things could you do?

A: 

I suppose @Deprecated would make sense. And maybe something like @Generated if the whole package was generated by some tool from non-Java source. Or @Internal if this package is not part of a public API.

Maybe OSGi tools (where you need to declare the versions of your packages, and the packages you depend on) could make use of this, too.

Has anyone seen those in the wild?

Thilo
+1  A: 

Two reasons that I can think of:

  • Annotating special packages to let some aspects (for example using AspectJ) to weave the classes in them for specific functionality.
  • Annotating some packages that are to be read by some tools, for example for source, meta-data or other kinds of resource generation.
Amir Moghimi
Are you saying that annotating a package is equivalent to annotating all classes within that package in one swoop?
Gili
No, I mean you can use it to indicate that the whole classes in that package should be weaved.
Amir Moghimi
How is that different from what I wrote?
Gili