The representation of annotations in class files is described in §4.7.16-§4.7.22. These sections make it clear how to represent annotations on declarations of classes, interfaces, fields, methods, method parameters, and type parameters, as well as annotations on types used in those declarations. Annotations on package declarations require additional rules, given here.
When the compiler encounters an annotated package declaration that must be made available at run time, it emits a class file with the following properties:
- The
classfile represents an interface, that is, theACC_INTERFACEandACC_ABSTRACTflags of theClassFilestructure are set (§4.1). - If the
classfile version number is less than 50.0, then theACC_SYNTHETICflag is unset; if theclassfile version number is 50.0 or above, then theACC_SYNTHETICflag is set. - The interface has package access (JLS §6.6.1).
- The interface's name is the internal form (§4.2.1) of
package-name.package-info. - The interface has no superinterfaces.
- The interface's only members are those implied by The Java Language Specification, Java SE 11 Edition (JLS §9.2).
- The annotations on the package declaration are stored as
RuntimeVisibleAnnotationsandRuntimeInvisibleAnnotationsattributes in theattributestable of theClassFilestructure.