ERROR - The member annotation can only be defined inside a top-level class or interface or in a static context

Error

The member annotation can only be defined inside a top-level class or interface or in a static context while using annotation types.

Error Type

Compile Time

Sample Code

public class BuggyBread {
   public static void main(String[] args) {
       public @interface Buggy {
       }

  }
}
Cause

The specified annotation is class member level and not method level.

Resolution

Make sure that the annotation has been added before the class or interface member or should have been in the static context and not within any method.

public class BuggyBread {
  
   public @interface Buggy {}
   public static void main(String[] args) {}
}