lundi 8 novembre 2021

How to get the value of a Type annotation

For example, here is a Type annotation called IntRange

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.TYPE_USE})
public @interface IntRange {
    public int min() default 0;
    public int max() default 5;
}

And here's a method which used it.

public boolean sumLessThan10(@ListLength(min = 0, max = 2) List<@IntRange(min = 5, max = 7) Integer> list) {
        return true;
    }

So how to get the value within @IntRange with reflection? And what if @IntRange is used in a nested list?





Aucun commentaire:

Enregistrer un commentaire