How can I get a generic type annotation

Andrey Romanyuk

Please tell me, how can I get annotations for a generic type?

Example: I have public List<@NotNull GuestForm> guests and I want to get NotNull annotation.

public class BookingForm {
    public List<@NotNull GuestForm> guests;

    private List<String> amenities;

    private String propertyType;

    private Unrelated unrelated;

    public BookingForm(List<GuestForm> guests, List<String> amenities, String propertyType, Unrelated unrelated) {
        this.guests = guests;
        this.amenities = amenities;
        this.propertyType = propertyType;
        this.unrelated = unrelated;
    }
}
Andrey Romanyuk
public class BookingForm {
    public List<@NotNull GuestForm> guests;

    private List<String> amenities;

    private String propertyType;

    private Unrelated unrelated;

    public BookingForm(List<GuestForm> guests, List<String> amenities, String propertyType, Unrelated unrelated) {
        this.guests = guests;
        this.amenities = amenities;
        this.propertyType = propertyType;
        this.unrelated = unrelated;
    }
}
Object objectClass = requireNonNull(bookingForm); 
var fields = objectClass.getClass().getDeclaredFields(); // Object fields
var annotations = ((AnnotatedParameterizedType) fields [0].getAnnotatedType()).getAnnotatedActualTypeArguments()[0].getAnnotations(); // Annotations of Generic type in List

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I get the generic type parameter of the 'this' parameter in an extension method?

From Dev

How can I get the generic type parameter of the 'this' parameter in an extension method?

From Dev

How can get the type of nested generic type

From Dev

How can get the type of nested generic type

From Dev

How to get the qualified class name of generic type in annotation processing?

From Dev

How do I access generic type in Macro Annotation in Scala?

From Dev

How do I access generic type in Macro Annotation in Scala?

From Dev

How to pass a type (generic) to an annotation?

From Dev

How can I pass generic type to generic methode?

From Dev

How can I get the values of an "enum" in a generic?

From Dev

how can I get method id for a function returning a generic type in jni?

From Dev

How can I get a valid type object for generic constraints in C#?

From Dev

How can I get a valid type object for generic constraints in C#?

From Dev

How can I get the fully qualified name of the runtime type of a generic parameter in Swift?

From Dev

How can I get this Typescript typeguard to work in a generic-type context?

From Dev

How can I check for array type (not generic type) in Kotlin

From Dev

Can I get Clazz.class on a generic type?

From Dev

Can I get Clazz.class on a generic type?

From Dev

How to parse Java annotation in generic type?

From Dev

How can I specify the type of the field that an Annotation should be applied to in Java?

From Dev

How can I require that a reference to a generic type can be compared for equality against the generic type?

From Dev

How can I get the type of a Type?

From Dev

How can I get tooltips showing in dygraphs without annotation

From Dev

How can I get the Declared Fields of a Java Class on an Annotation Processor?

From Dev

How can I generate any generic type at runtime on AOT platforms?

From Dev

How can I create a generic collection which contains a specific type?

From Dev

How do I write a function that can iterate over a generic type

From Dev

How can I alias a covariant generic type parameter

From Dev

How can I specialize a method for a specific generic type?

Related Related

  1. 1

    How can I get the generic type parameter of the 'this' parameter in an extension method?

  2. 2

    How can I get the generic type parameter of the 'this' parameter in an extension method?

  3. 3

    How can get the type of nested generic type

  4. 4

    How can get the type of nested generic type

  5. 5

    How to get the qualified class name of generic type in annotation processing?

  6. 6

    How do I access generic type in Macro Annotation in Scala?

  7. 7

    How do I access generic type in Macro Annotation in Scala?

  8. 8

    How to pass a type (generic) to an annotation?

  9. 9

    How can I pass generic type to generic methode?

  10. 10

    How can I get the values of an "enum" in a generic?

  11. 11

    how can I get method id for a function returning a generic type in jni?

  12. 12

    How can I get a valid type object for generic constraints in C#?

  13. 13

    How can I get a valid type object for generic constraints in C#?

  14. 14

    How can I get the fully qualified name of the runtime type of a generic parameter in Swift?

  15. 15

    How can I get this Typescript typeguard to work in a generic-type context?

  16. 16

    How can I check for array type (not generic type) in Kotlin

  17. 17

    Can I get Clazz.class on a generic type?

  18. 18

    Can I get Clazz.class on a generic type?

  19. 19

    How to parse Java annotation in generic type?

  20. 20

    How can I specify the type of the field that an Annotation should be applied to in Java?

  21. 21

    How can I require that a reference to a generic type can be compared for equality against the generic type?

  22. 22

    How can I get the type of a Type?

  23. 23

    How can I get tooltips showing in dygraphs without annotation

  24. 24

    How can I get the Declared Fields of a Java Class on an Annotation Processor?

  25. 25

    How can I generate any generic type at runtime on AOT platforms?

  26. 26

    How can I create a generic collection which contains a specific type?

  27. 27

    How do I write a function that can iterate over a generic type

  28. 28

    How can I alias a covariant generic type parameter

  29. 29

    How can I specialize a method for a specific generic type?

HotTag

Archive