Annotations – Custom Annotation in Java


Custom annotations can convey metadata about your program elements.

Source Code

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyCustomAnnotation {
    int value();
}

class MyClass {
    @MyCustomAnnotation(value = 10)
    public void myMethod() {}
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments