> ## 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 Target Annotation

The `@Target` meta-annotation in Kotlin dictates the specific syntactic elements to which a custom annotation can be applied. By applying `@Target` to an annotation class declaration, the compiler enforces structural constraints, preventing the annotation from being attached to invalid language constructs during compilation.

It accepts a `vararg` of `kotlin.annotation.AnnotationTarget` enum values.

```kotlin theme={"dark"}
@Target(
    AnnotationTarget.CLASS,
    AnnotationTarget.FUNCTION,
    AnnotationTarget.VALUE_PARAMETER
)
annotation class RestrictedAnnotation
```

## The `AnnotationTarget` Enum

The `AnnotationTarget` enum provides granular control over Kotlin's language features, which often map to multiple underlying JVM elements. The available targets include:

* **`CLASS`**: Classes, interfaces, objects, and annotation classes.
* **`ANNOTATION_CLASS`**: Restricted exclusively to other annotation classes (used for defining meta-annotations).
* **`TYPE_PARAMETER`**: Generic type parameter declarations (e.g., `<T>`).
* **`PROPERTY`**: Kotlin properties.
* **`FIELD`**: Backing fields of properties.
* **`LOCAL_VARIABLE`**: Variables declared within a function or block scope.
* **`VALUE_PARAMETER`**: Parameters of functions or constructors.
* **`CONSTRUCTOR`**: Primary or secondary constructors.
* **`FUNCTION`**: Functions (excluding constructors).
* **`PROPERTY_GETTER` / `PROPERTY_SETTER`**: Explicit or implicit property accessors.
* **`TYPE`**: Type usages (e.g., the type specified in a variable declaration, function return type, or supertype).
* **`EXPRESSION`**: Arbitrary expressions.
* **`FILE`**: File-level declarations.
* **`TYPEALIAS`**: Typealias declarations.

## Default Behavior

If the `@Target` meta-annotation is omitted from an annotation class declaration, the Kotlin compiler applies a default set of targets. The annotation implicitly becomes applicable to: `CLASS`, `PROPERTY`, `FIELD`, `LOCAL_VARIABLE`, `VALUE_PARAMETER`, `CONSTRUCTOR`, `FUNCTION`, `PROPERTY_GETTER`, and `PROPERTY_SETTER`. It implicitly excludes `TYPE`, `TYPE_PARAMETER`, `EXPRESSION`, `FILE`, and `TYPEALIAS` (note that `ANNOTATION_CLASS` is technically covered by the inclusion of `CLASS`).

## Resolution and Use-Site Targets

Because a primary constructor parameter declared with `val` or `var` simultaneously declares a property, it can generate multiple underlying JVM elements (the constructor parameter, a backing field, a getter, and a setter). The `@Target` annotation dictates how the compiler resolves ambiguous applications in these overlapping constructs.

If an annotation's `@Target` includes both `PROPERTY` and `FIELD`, applying it to a property declaration defaults to the `PROPERTY` target. To force the annotation onto the backing field or an accessor, the developer must use use-site target syntax, provided those targets are explicitly permitted by the annotation's `@Target` declaration.

```kotlin theme={"dark"}
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
annotation class DualTargetAnnotation

class Example {
    // Resolves to AnnotationTarget.PROPERTY based on default compiler resolution
    @DualTargetAnnotation 
    val defaultTarget: String = ""

    // Explicitly resolves to AnnotationTarget.FIELD using use-site syntax
    @field:DualTargetAnnotation 
    val explicitTarget: String = ""
}
```

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