Currently I have been thinking about the question however, I couldn't find a proper answer. Use case at hand is to create an implementation class for a particular custom annotation so that in the runtime I can simply generate it instead of a POJO.
For instance:
Annotation:
@interface CustomAnnotation {
String date();
}
At this stage I need a bean which happens to have the same fields as the annotation. Here I have two options either implement the annotation and create it in runtime or create a class to carry the information.
A) Implementation of Annotation:
public class CustomAnnotationImpl implements CustomAnnotation {
private final String date;
public CustomAnnotationImpl(String date) {
this.date = date;
}
@Override
public String date() {
return this.date;
}
@Override
public Class<? extends Annotation> annotationType() {
return CustomAnnotation.class;
}
}
B)
public class CustomBean {
private final String date;
public CustomAnnotationImpl(String date) {
this.date = date;
}
public String getDate() {
return this.date;
}
}
Also keep in my mind that the bean and annotation will be always in sync meaning that bean actually will be always a copy of the annotation.
My question is that what would be the advantages and drawbacks of those, if any? I'm asking this because simply I haven't seen implementation of annotation myself.