> ## 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.

# Kotlin Repeatable Annotation

A repeatable annotation in Kotlin is a custom annotation configured with the `@kotlin.annotation.Repeatable` meta-annotation, allowing it to be applied multiple times to the exact same target element (such as a class, function, or property) within a single declaration.

## Declaration and Syntax

To define a repeatable annotation, apply the `@Repeatable` meta-annotation to an `annotation class`. Kotlin automatically handles the generation of the underlying container annotation required to group multiple instances.

```kotlin theme={"dark"}
@Repeatable
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class Tag(val name: String)
```

Once defined, the annotation can be stacked sequentially on a single target:

```kotlin theme={"dark"}
@Tag("core")
@Tag("experimental")
class Component
```

## Compiler Mechanics and Retention

When the Kotlin compiler encounters multiple instances of a repeatable annotation, it implicitly generates a container annotation to hold the array of annotation instances.

* **Native Support:** Since Kotlin 1.6, repeatable annotations are supported natively. The compiler automatically generates a nested `Container` annotation (e.g., `Tag.Container`) to hold the array of values.
* **Retention Policies:** Kotlin's native `@kotlin.annotation.Repeatable` fully supports all retention policies, including `AnnotationRetention.SOURCE`, `AnnotationRetention.BINARY`, and `AnnotationRetention.RUNTIME`.

## Java Interoperability

Kotlin's native `@kotlin.annotation.Repeatable` automatically makes the annotation repeatable in Java. The Kotlin compiler achieves this by implicitly generating the nested `Container` annotation class, which Java 8+ recognizes as the standard container for the repeatable annotation.

The `@JvmRepeatable` meta-annotation is only required if you must specify a *custom* explicit container class. This is typically necessary only for backward compatibility with an existing Java codebase that expects a specific, pre-defined container annotation name rather than Kotlin's default nested `Container`.

```kotlin theme={"dark"}
// 1. Explicitly define a custom container annotation
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class LegacyTagContainer(val value: Array<Tag>)

// 2. Apply @JvmRepeatable and link it to the custom container class
@JvmRepeatable(LegacyTagContainer::class)
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
annotation class Tag(val name: String)
```

## Runtime Retrieval via Reflection

To extract multiple instances of a repeatable annotation at runtime, use the `findAnnotations<T>()` extension function from the `kotlin.reflect.full` package. This function automatically unwraps the implicit or explicit container and returns a list of the annotation instances.

```kotlin theme={"dark"}
import kotlin.reflect.full.findAnnotations

fun inspectAnnotations() {
    val tags = Component::class.findAnnotations<Tag>()
    
    tags.forEach { tag ->
        println(tag.name)
    }
}
// Output:
// core
// experimental
```

<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 Kotlin 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>
