jeudi 24 novembre 2016

Link annotations on type parameters in subtypes to declaring type parameters in supertype

Let there be a type extending java.util.Map:

public interface IdentifiableMap<ID, KEY, VALUE> extends Map<KEY, VALUE>{

    ID getId();
}

Also let there be a field of that type which declares an annotation on one of the type parameters (as it's possible as of Java 8):

private IdentifiableMap<String, @Size(min=1) String, Integer> myMap = ...;

Using the Java reflection API, how can I find out from this declaration which annotations have been given for the type parameters from the Map interface? In other words, I'd like to deduct that the @Size annotation has been given for the K type parameter of java.util.Map.

I know how to obtain the annotations for the type parameters from the field's AnnotatedParameterizedType, but I'm missing how to correlate this to the type parameters of the super type Map.





Aucun commentaire:

Enregistrer un commentaire