---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 25 Edition"
java_version: 25
chapter: "Chapter 9. Interfaces"
section: "9.6"
heading: "9.6. Annotation Interfaces"
parent: "Chapter 9. Interfaces"
source: https://docs.oracle.com/javase/specs/jls/se25/html/jls-9.html#jls-9.6
id: "9.6"
url: https://jvm.obfuscated.software/jls/se25/9.6.html
raw: https://jvm.obfuscated.software/jls/se25/9.6.md
---

# 9.6. Annotation Interfaces

An *annotation interface declaration* specifies an *annotation interface*, a specialized kind of interface. To distinguish an annotation interface declaration from a normal interface declaration, the keyword `interface` is preceded by an at sign (`@`).

```
AnnotationInterfaceDeclaration:
  {InterfaceModifier} @ interface TypeIdentifier AnnotationInterfaceBody
```

Note that the at sign (`@`) and the keyword `interface` are distinct tokens. It is possible to separate them with whitespace, but this is discouraged as a matter of style.

Unless explicitly modified in this section and its subsections, all of the rules that apply to normal interface declarations ([§9.1](9.1.md)) apply to annotation interface declarations.

For example, annotation interface declarations have the same rules for scope as normal interface declarations.

It is a compile-time error if an annotation interface declaration has the modifier `sealed` or `non-sealed` ([§9.1.1.4](9.1.1.4.md)).

An annotation interface declaration may specify a top level interface or a member interface, but not a local interface ([§14.3](14.3.md)).

An annotation interface declaration is not permitted syntactically to appear within a block, by virtue of the *LocalClassOrInterfaceDeclaration* production in [§14.3](14.3.md).

It is a compile-time error if an annotation interface declaration appears directly or indirectly in the body of a local class, local interface, or anonymous class declaration ([§14.3](14.3.md), [§15.9.5](15.9.5.md)).

This rule, together with the syntactic restriction on annotation interface declarations noted above, ensures that an annotation interface always has a canonical name ([§6.7](6.7.md)). Having such a name is important because the purpose of an annotation interface is to be used by annotations in other compilation units. Since a local class or interface does not have a canonical name, an annotation interface declared anywhere within its syntactic body (if that were allowed) would not have a canonical name either.

The following code shows the effect of this rule and the related syntactic restriction:

```
class C {
    @interface A1 {}  /* Legal: an annotation interface can be a
                         member interface */

    void m() {
        @interface A2 {}  /* Illegal: an annotation interface cannot
                             be a local interface */

        class D {
            @interface A3 {}  /* Illegal: an annotation interface
                                 cannot be specified anywhere within
                                 the body of local class D */

            class E {
                @interface A4 {}
                  /* Illegal: an annotation interface cannot be
                     specified anywhere within the body of local class
                     D, even as a member of a class E nested in D */
            }
        }
    }
}
```

An annotation interface is never generic ([§9.1.2](9.1.2.md)).

Unlike a normal interface declaration, an annotation interface declaration cannot declare any type variables, by virtue of the *AnnotationTypeDeclaration* production.

The direct superinterface type of an annotation interface is always `java.lang.annotation.Annotation` ([§9.1.3](9.1.3.md)).

Unlike a normal interface declaration, an annotation interface declaration cannot choose the direct superinterface type via an `extends` clause, by virtue of the *AnnotationTypeDeclaration* production.

A consequence of the fact that an annotation interface declaration does not explicitly specify a superinterface type via `extends` is that a subinterface of an annotation interface is never itself an annotation interface, since the subinterface's declaration necessarily uses an `extends` clause. Similarly, `java.lang.annotation.Annotation` is not itself an annotation interface.

An annotation interface inherits several methods from `java.lang.annotation.Annotation`, including the implicitly declared methods corresponding to the instance methods of `Object` ([§9.2](9.2.md)), yet these methods do not define elements of the annotation interface ([§9.6.1](9.6.1.md)).

Because these methods do not define elements of the annotation interface, it is illegal to use them in annotations conforming to the annotation interface ([§9.7](9.7.md)). Without this rule, we could not ensure that elements were of the types representable in annotations, or that accessor methods for them would be available.

**Sections:**

- [9.6.1. Annotation Interface Elements](9.6.1.md)
- [9.6.2. Defaults for Annotation Interface Elements](9.6.2.md)
- [9.6.3. Repeatable Annotation Interfaces](9.6.3.md)
- [9.6.4. Predefined Annotation Interfaces](9.6.4.md)
