Class Annotations


  • public final class Annotations
    extends Object
    Useful methods for working with Java annotations.
    Author:
    Mark Hiner, Curtis Rueden
    • Method Detail

      • annotatedMethods

        public static <A extends AnnotationList<Method> annotatedMethods​(Class<?> c,
                                                                           Class<A> annotationClass)
        Gets the given class's Methods marked with the annotation of the specified class.

        Unlike Class.getMethods(), the result will include any non-public methods, including methods defined in supertypes of the given class.

        Parameters:
        c - The class to scan for annotated methods.
        annotationClass - The type of annotation for which to scan.
        Returns:
        A list containing all methods with the requested annotation. Note that for performance reasons, lists may be cached and reused, so it is best to make a copy of the result if you need to modify it.
      • annotatedMethods

        public static <A extends Annotation> void annotatedMethods​(Class<?> c,
                                                                   Class<A> annotationClass,
                                                                   List<Method> methods)
        Gets the given class's Methods marked with the annotation of the specified class.

        Unlike Class.getMethods(), the result will include any non-public methods, including methods defined in supertypes of the given class.

        Parameters:
        c - The class to scan for annotated methods.
        annotationClass - The type of annotation for which to scan.
        methods - The list to which matching methods will be added.
      • annotatedFields

        public static <A extends AnnotationList<Field> annotatedFields​(Class<?> c,
                                                                         Class<A> annotationClass)
        Gets the given class's Fields marked with the annotation of the specified class.

        Unlike Class.getFields(), the result will include any non-public fields, including fields defined in supertypes of the given class.

        Parameters:
        c - The class to scan for annotated fields.
        annotationClass - The type of annotation for which to scan.
        Returns:
        A list containing all fields with the requested annotation. Note that for performance reasons, lists may be cached and reused, so it is best to make a copy of the result if you need to modify it.
      • annotatedFields

        public static <A extends Annotation> void annotatedFields​(Class<?> c,
                                                                  Class<A> annotationClass,
                                                                  List<Field> fields)
        Gets the given class's Fields marked with the annotation of the specified class.

        Unlike Class.getFields(), the result will include any non-public fields, including fields defined in supertypes of the given class.

        Parameters:
        c - The class to scan for annotated fields.
        annotationClass - The type of annotation for which to scan.
        fields - The list to which matching fields will be added.