> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java Annotation Interface

A Java annotation interface is a specialized interface type declared using the `@interface` keyword, utilized to define custom annotations. At compile time, the Java compiler generates a `.class` file for this declaration with both the `ACC_INTERFACE` and `ACC_ANNOTATION` flags set. It remains a specialized annotation interface at the bytecode level and implicitly extends the `java.lang.annotation.Annotation` interface. Because of this implicit inheritance, an annotation interface cannot explicitly extend other interfaces.

## Syntax and Declaration

The declaration replaces the standard `interface` keyword with `@interface`.

```java theme={"dark"}
public @interface StandardAnnotation {
    // Element declarations
}
```

## Annotation Elements

Data within an annotation interface is defined using method declarations, which act as the annotation's attributes or elements. These elements are implicitly `public` and `abstract`. Unlike standard interfaces, annotation interfaces are strictly prohibited from declaring `default` or `private` methods.

Elements are subject to strict compiler rules:

1. **No Parameters:** The method declaration must not accept any arguments.
2. **No Exceptions:** The method must not have a `throws` clause.
3. **No Type Parameters:** Generic methods are not permitted.
4. **No Cyclic Dependencies:** An annotation interface cannot contain an element of its own type, either directly or indirectly.

```java theme={"dark"}
public @interface ConfigMetadata {
    String author();
    int revision();
}
```

## Permitted Return Types

The return type of an annotation element is strictly limited to the following:

* Primitive types (`int`, `boolean`, `double`, etc.)
* `java.lang.String`
* `java.lang.Class` (including parameterized forms like `Class<?>` or `Class<? extends Number>`)
* `enum` types
* Other annotation interfaces
* Single-dimensional arrays of any of the types listed above

```java theme={"dark"}
import java.lang.annotation.ElementType;

public @interface ComplexAnnotation {
    boolean isEnabled();                  // Primitive
    String[] tags();                      // Array of String
    Class<?> targetClass();               // Class type
    ElementType targetEnum();             // Enum type
    StandardAnnotation nestedConfig();    // Nested annotation
}
```

## Default Values

Elements can be assigned default values using the `default` keyword. If a default value is provided, the element becomes optional when the annotation is applied.

**Crucial constraint:** An annotation element can never evaluate to `null`. Therefore, default values cannot be `null`, and arrays cannot contain `null` elements.

```java theme={"dark"}
public @interface Timeout {
    int duration() default 1000;
    String unit() default "MILLISECONDS";
    String[] fallbackMethods() default {}; // Empty array instead of null
}
```

## The `value` Element

If an annotation interface declares an element named exactly `value`, and it is the only element specified when the annotation is applied (or all other elements have default values), the element name `value=` can be omitted during application.

```java theme={"dark"}
public @interface SingleValueAnnotation {
    String[] value();
}
```

## Meta-Annotations

An annotation interface is typically decorated with meta-annotations—annotations applied to other annotations—to define its behavior and scope within the JVM and compiler:

* **`@Target`**: Specifies the Java elements (e.g., `TYPE`, `METHOD`, `FIELD`) to which the annotation interface can be applied.
* **`@Retention`**: Dictates the lifecycle of the annotation (`SOURCE`, `CLASS`, or `RUNTIME`).
* **`@Inherited`**: Indicates that the annotation should be automatically inherited by subclasses of the annotated class.
* **`@Documented`**: Instructs Javadoc to include the annotation in the generated documentation.
* **`@Repeatable`**: Allows the same annotation interface to be applied multiple times to a single declaration.

```java theme={"dark"}
import java.lang.annotation.*;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ScopedAnnotation {
    String value() default "singleton";
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
