I wrote this simple annotation:
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})
public @interface CSVColumn {
String name();
int order();
}
which I'm currently using to annotate some getter methods of a class. I'm able to get the values of this annotation at runtime:
Class classType = objects[0].getClass();
Method[] methodsArray = classType.getDeclaredMethods();
List<Method> methods = Arrays.asList(methodsArray);
//FIlter annotated methods
methods = methods.stream().filter(method -> method.getAnnotation(CSVColumn.class) != null).collect(Collectors.toList());
Iterator<Method> methodIterator = methods.iterator();
while (methodIterator.hasNext()) {
Method method = methodIterator.next();
CSVColumn csvColumn = method.getAnnotation(CSVColumn.class);
String header = csvColumn.name();
}
but how could I set the field name of the annotation to another value? Should/could I declare some setter methods in the annotation class?