Skip to content

Instantly share code, notes, and snippets.

@iamitshri
Created October 9, 2018 21:02
Show Gist options
  • Save iamitshri/2f5ca5a7dc25ba736d42a9888a3f0afa to your computer and use it in GitHub Desktop.
Save iamitshri/2f5ca5a7dc25ba736d42a9888a3f0afa to your computer and use it in GitHub Desktop.
Read Annotations on class using Reflection
// 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