Last active
April 22, 2016 03:34
-
-
Save apolaskey/2480d5c6c1a56bd5ea89 to your computer and use it in GitHub Desktop.
Find all Methods with Annotation
This file contains hidden or 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
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