Annotations can be declared to include elements that act like methods. This feature allows annotations to carry additional information accessible at runtime, enhancing their utility for tasks like configuration, parsing, or validation.
Source Code
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyCustomAnnotation {
String description() default "No description";
}
class UseAnnotation {
@MyCustomAnnotation(description = "This is a custom annotation")
public void myMethod() {}
}