Skip to content

Instantly share code, notes, and snippets.

@apolaskey
Last active April 22, 2016 03:34
Show Gist options
  • Save apolaskey/2480d5c6c1a56bd5ea89 to your computer and use it in GitHub Desktop.
Save apolaskey/2480d5c6c1a56bd5ea89 to your computer and use it in GitHub Desktop.
Find all Methods with Annotation
public static List<Method> getMethodsAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation) {
final List<Method> methods = new ArrayList<>();
Class<?> klass = type;
while (klass != Object.class) {
final List<Method> allMethods = new ArrayList<>(Arrays.asList(klass.getDeclaredMethods()));
allMethods.stream()
.filter(method -> method.isAnnotationPresent(annotation))
.forEach(methods::add);
klass = klass.getSuperclass();
}
return methods;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment