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

# 9.6. Annotation Types

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

```
AnnotationTypeDeclaration:
  {InterfaceModifier} @ interface Identifier AnnotationTypeBody
```

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.

The rules for annotation modifiers on an annotation type declaration are specified in [§9.7.4](9.7.4.md) and [§9.7.5](9.7.5.md).

The *Identifier* in an annotation type declaration specifies the name of the annotation type.

It is a compile-time error if an annotation type has the same simple name as any of its enclosing classes or interfaces.

The direct superinterface of every annotation type is `java.lang.annotation.Annotation`.

By virtue of the *AnnotationTypeDeclaration* syntax, an annotation type declaration cannot be generic, and no `extends` clause is permitted.

A consequence of the fact that an annotation type cannot explicitly declare a superclass or superinterface is that a subclass or subinterface of an annotation type is never itself an annotation type. Similarly, `java.lang.annotation.Annotation` is not itself an annotation type.

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

Because these methods do not define elements of the annotation type, it is illegal to use them in annotations of that type ([§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.

Unless explicitly modified herein, all of the rules that apply to normal interface declarations apply to annotation type declarations.

For example, annotation types share the same namespace as normal class and interface types; and annotation type declarations are legal wherever interface declarations are legal, and have the same scope and accessibility.

**Sections:**

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