Created
October 9, 2018 21:02
-
-
Save iamitshri/2f5ca5a7dc25ba736d42a9888a3f0afa to your computer and use it in GitHub Desktop.
Read Annotations on class using Reflection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get annotations on the class object | |
Annotation[] annotations = classobject.getClass() | |
.getAnnotations(); | |
for (Annotation annotation : annotations) { | |
log.debug("annotation type: {}", annotation.annotationType()); | |
Class<? extends Annotation> type = annotation.annotationType(); | |
for (Method method : type.getDeclaredMethods()) { | |
Object val = method.invoke(annotation, (Object[]) null); | |
log.debug("method name: {}, return value:{} return type:{}", method.getName(), val, val.getClass() | |
.getName()); | |
} | |
log.debug(annotation.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment