Checking if an annotation is of a specific type

后端 未结 5 1574
生来不讨喜
生来不讨喜 2021-02-01 20:57

I am using reflection to see if an annotation that is attached to a property of a class, is of a specific type. Current I am doing:

if(\"javax.validation.Valid\"         


        
5条回答
  •  花落未央
    2021-02-01 21:55

    Just for completeness' sake, another possibility is

    if (this.getClass().isAnnotationPresent(MyCustomAnnotation.class)) {
    

提交回复
热议问题