# java.lang.annotation

***

**1. Type Annotation with Retention Policy**

```java
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    String value();
}

@MyAnnotation("Example Value")
public class MyClass {
    // ...
}
```

**2. Method Parameter Annotation**

```java
public void myMethod(@MyAnnotation String parameter) {
    // ...
}
```

**3. Method Return Value Annotation**

```java
@MyAnnotation
public String myMethod() {
    // ...
    return "Example Value";
}
```

**4. Field Annotation**

```java
public class MyClass {
    @MyAnnotation
    private String myField;
    // ...
}
```

**5. Type Annotation with Multiple Values**

```java
@MyAnnotation({ "Value 1", "Value 2" })
public class MyClass {
    // ...
}
```

**6. Type Annotation with Default Value**

```java
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    String value() default "Default Value";
}

@MyAnnotation
public class MyClass {
    // ...
}
```

**7. Type Annotation with Alias**

```java
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    String name() alias for "value";
}

@MyAnnotation(name = "Example Value")
public class MyClass {
    // ...
}
```

**8. Method Parameter Annotation with Nested Annotation**

```java
@MyAnnotationNested(value = "Nested Value")
public void myMethod(@MyAnnotation String parameter) {
    // ...
}
```

**9. Method Return Value Annotation with Nested Annotation**

```java
@MyAnnotationNested(value = "Nested Value")
public String myMethod() {
    // ...
    return "Example Value";
}
```

**10. Field Annotation with Nested Annotation**

```java
public class MyClass {
    @MyAnnotationNested(value = "Nested Value")
    private String myField;
    // ...
}
```

**11. Type Annotation with Retention Policy and Target**

```java
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
public @interface MyAnnotation {
    String value();
}
```

**12. Type Annotation with Inheritance**

```java
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    String value();
}

public class Superclass {
    @MyAnnotation("Superclass Value")
    // ...
}

public class Subclass extends Superclass {
    // ...
}
```

**13. Type Annotation with Documentation**

```java
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    String value();
}
```

**14. Type Annotation for JUnit Testing**

```java
import org.junit.jupiter.api.Test;

@MyAnnotation
@Test
public void myTest() {
    // ...
}
```

**15. Type Annotation for Database Mapping**

```java
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
@MyAnnotation
public class MyEntity {
    @Id
    private Long id;
    // ...
}
```

**16. Type Annotation for Dependency Injection**

```java
import javax.inject.Qualifier;

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    String value();
}
```

**17. Type Annotation for Logging**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface Loggable {
    Level value() default Level.INFO;
}
```

**18. Type Annotation for Configuration**

```java
import org.springframework.context.annotation.Configuration;

@Configuration
@MyAnnotation
public class MyConfiguration {
    // ...
}
```

**19. Type Annotation for Metrics Collection**

```java
import io.micrometer.core.annotation.Timed;

@Timed
public void myMethod() {
    // ...
}
```

**20. Type Annotation for Tracing**

```java
import io.opentelemetry.api.trace.SpanKind;

@SpanKind(SpanKind.SERVER)
public void myMethod() {
    // ...
}
```

**21. Type Annotation for Security**

```java
import javax.annotation.security.RolesAllowed;

@RolesAllowed("ADMIN")
public void myMethod() {
    // ...
}
```

**22. Type Annotation for XML Serialization**

```java
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class MyObject {
    // ...
}
```

**23. Type Annotation for JSON Serialization**

```java
import com.fasterxml.jackson.annotation.JsonProperty;

public class MyObject {
    @JsonProperty("my_property")
    private String myProperty;
    // ...
}
```

**24. Type Annotation for Swagger Documentation**

```java
import io.swagger.annotations.ApiOperation;

@ApiOperation("My Operation")
public void myMethod() {
    // ...
}
```

**25. Type Annotation for REST API**

```java
import javax.ws.rs.Path;
import javax.ws.rs.GET;

@Path("/my-resource")
public class MyResource {
    @GET
    public String myMethod() {
        // ...
        return "Example Response";
    }
}
```

**26. Type Annotation for Event Handling**

```java
import org.springframework.context.event.EventListener;

public class MyEventListener {
    @EventListener
    public void handleMyEvent(MyEvent event) {
        // ...
    }
}
```

**27. Type Annotation for Task Scheduling**

```java
import org.springframework.scheduling.annotation.Scheduled;

public class MyTask {
    @Scheduled(cron = "0 * * * * *")
    public void myScheduledTask() {
        // ...
    }
}
```

**28. Type Annotation for Aspect-Oriented Programming**

```java
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class MyAspect {
    @Before("execution(* myMethod())")
    public void myAdvice() {
        // ...
    }
}
```

**29. Type Annotation for Code Coverage**

```java
import org.jacoco.agent.rt.EnableJaCoCo;

@EnableJaCoCo
public class MyTestClass {
    // ...
}
```

**30. Type Annotation for SonarQube Code Quality**

```java
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Rule;
import org.sonar.api.rule.RuleCategory;

@Rule(key = RuleKey.of("my-rule"))
@RuleCategory(RuleCategory.BUG)
public class MySonarQubeRule {
    // ...
}
```

**31. Type Annotation for Kotlin Coroutines**

```kotlin
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.flow.Flow

@InternalCoroutinesApi
@FlowPreview
fun myFlow(): Flow<Int> {
    // ...
}
```

**32. Type Annotation for Java 9+**

```java
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}

@MyAnnotation("Value 1")
@MyAnnotation("Value 2")
public class MyClass {
    // ...
}
```

**33. Type Annotation for Java 10+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
public @interface MyAnnotation {
    String value();
}
```

**34. Type Annotation for Java 11+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**35. Type Annotation for Java 12+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**36. Type Annotation for Java 13+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**37. Type Annotation for Java 14+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**38. Type Annotation for Java 15+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**39. Type Annotation for Java 16+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**40. Type Annotation for Java 17+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**41. Type Annotation for Java 18+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**42. Type Annotation for Java 19+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**43. Type Annotation for Java 20+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**44. Type Annotation for Java 21+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**45. Type Annotation for Java 22+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

**46. Type Annotation for Java 23+**

```java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.annotation.Repeatable;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Repeatable(MyAnnotations.class)
public @interface MyAnnotation {
    String value();
}
```

\*\*47. Type Annotation for Java
