Search code examples
javaannotationspackagejavadoc

How do I add package level annotations or edit package-info.java?


I'm trying to add package level annotations but I don't have a clue on how to do it. Examples are appreciated.


Solution

  • Summary from the article here

    In package-info.java:

    @PackageLevelAnnotation
    package blammy; // package with a package level annotation.
    
    
    import blammy.annotation.PackageLevelAnnotation;
    

    In PackageLevelAnnotation.java

    package blammy.annotation;
    
    @Retention(RetentionPolicy.CLASS)
    @Target(ElementType.PACKAGE)
    public @interface PackageLevelAnnotation
    {
      // stuff as required.
    }
    

    Edit: more package level info. Here is a link to the package chapter in the Java Language Spec: packages