Class Annotations

    • Method Detail

      • getAnnotationAttributeValues

        public static <A extends Annotation,​T> Stream<T> getAnnotationAttributeValues​(Class<?> classToTest,
                                                                                            Class<A> annotationClass,
                                                                                            BiFunction<A,​Class<?>,​T> annotationAttributeGetter)
        Gets the Annotations on any of the superclasses or on any of the implemented interfaces from the given class to test, and then apply a bifunction on it (generally to obtain attributes from the Annotation instance).
        Unlike Class.getAnnotation(java.lang.Class<A>), it also checks into all the implemented interfaces.
        Whereas the whole hierarchy is traversed, the meta-annotation Inherited can have some effects depending on the operations you process on the result Stream, as the same annotation instance will be provided to the BiFunction with different classes (which are related, one being the superclass of all the others).
        Type Parameters:
        A - The runtime type of the Annotation
        T - The type of results to get
        Parameters:
        classToTest - The class to test
        annotationClass - The Annotation class
        annotationAttributeGetter - The two-args function to apply to get the final results. The two arguments represent the Annotation instance and the class which is annotated (be careful if the Annotation class has the meta-annotation Inherited).
        Returns:
        a Stream of T elements returned by the bifunction applied on Annotations instances on any of the superclasses or on any of the implemented interfaces or on the provided class itself.