@Test void getMethodsAnnotatedWith() { Set<Method> methods = ReflectionUtils.getMethodsAnnotatedWith(Bar.class, AnnotationTest.class); Assertions.assertEquals(2, methods.size()); methods.forEach(method -> Assertions.assertEquals("test", method.getName())); }
public static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation) { Set<Method> methods = new HashSet<>(); Class<?> currentClazz = clazz; while (currentClazz != Object.class) { methods.addAll(Arrays.stream(currentClazz.getDeclaredMethods()) .filter(method -> method.isAnnotationPresent(annotation)) .collect(Collectors.toList())); currentClazz = currentClazz.getSuperclass(); } return methods; }
ReflectionUtils { public static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation) { Set<Method> methods = new HashSet<>(); Class<?> currentClazz = clazz; while (currentClazz != Object.class) { methods.addAll(Arrays.stream(currentClazz.getDeclaredMethods()) .filter(method -> method.isAnnotationPresent(annotation)) .collect(Collectors.toList())); currentClazz = currentClazz.getSuperclass(); } return methods; } }
ReflectionUtils { public static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation) { Set<Method> methods = new HashSet<>(); Class<?> currentClazz = clazz; while (currentClazz != Object.class) { methods.addAll(Arrays.stream(currentClazz.getDeclaredMethods()) .filter(method -> method.isAnnotationPresent(annotation)) .collect(Collectors.toList())); currentClazz = currentClazz.getSuperclass(); } return methods; } private  ReflectionUtils(); }
ReflectionUtils { public static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation) { Set<Method> methods = new HashSet<>(); Class<?> currentClazz = clazz; while (currentClazz != Object.class) { methods.addAll(Arrays.stream(currentClazz.getDeclaredMethods()) .filter(method -> method.isAnnotationPresent(annotation)) .collect(Collectors.toList())); currentClazz = currentClazz.getSuperclass(); } return methods; } private  ReflectionUtils(); static Collection<E> getByModifier(E[] executables, int modifier); static Option<Method> getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes); static List<Method> getMethods(Class<?> clazz, String methodName); static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation); static Collection<T> getStaticFieldValues(Class<?> clazz, Class<T> type); @SuppressWarnings("unchecked") static Collection<R> getFieldValues(Class<T> clazz, Class<R> type, @Nullable T instance); }
ReflectionUtils { public static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation) { Set<Method> methods = new HashSet<>(); Class<?> currentClazz = clazz; while (currentClazz != Object.class) { methods.addAll(Arrays.stream(currentClazz.getDeclaredMethods()) .filter(method -> method.isAnnotationPresent(annotation)) .collect(Collectors.toList())); currentClazz = currentClazz.getSuperclass(); } return methods; } private  ReflectionUtils(); static Collection<E> getByModifier(E[] executables, int modifier); static Option<Method> getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes); static List<Method> getMethods(Class<?> clazz, String methodName); static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation); static Collection<T> getStaticFieldValues(Class<?> clazz, Class<T> type); @SuppressWarnings("unchecked") static Collection<R> getFieldValues(Class<T> clazz, Class<R> type, @Nullable T instance);  }