Assuming I have the following member in a class which makes use of Java 8 type annotations:
private List<@Email String> emailAddresses;
Is it possible to read the @Email
annotation given on the String type use at runtime using reflection? If so, how would this be done?
Update: That's the definition of the annotation type:
@Target(value=ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Email {}
Yes it is possible. The reflection type representing this kind of structure is called
AnnotatedParameterizedType
. Here is an example of how to get your annotation: