1 | initial version |
You can include a personalized attribute or metadata to a java file using annotations.
Example:
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MyAnnotation {
String author() default "John Doe";
String date();
}
Example:
@MyAnnotation(date = "2021-10-21")
public class MyClass {
// Your code here
}
Example:
MyAnnotation annotation = MyClass.class.getAnnotation(MyAnnotation.class);
String author = annotation.author(); // "John Doe"
String date = annotation.date(); // "2021-10-21"
By using annotations, you can add customized attributes to your Java files and retrieve them at runtime.