Skip to content
Luke Hutchison edited this page Aug 11, 2026 · 6 revisions

See also the ClassGraph API overview.

Contents

AnnotationInfo

Holds information about one concrete annotation instance, for an annotation on a class, field, method, method parameter, package or module. Obtained by calling .getAllAnnotationInfo() or .getDirectAnnotationInfo() on a ClassInfo, FieldInfo, MethodInfo, MethodParameterInfo, PackageInfo or ModuleInfo object.

This is the information about a concrete annotation in the sense that it contains information not just about the annotating class, but also the specific annotation parameters, which may or may not override default annotation parameter values associated with the annotation class.

  • Properties: (N.B. call .enableAnnotationInfo() before .scan() to enable annotation scanning, and call .ignoreClassVisibility() if you want to scan non-public annotation classes.)
    • .getName() returns the name of the annotation as a String.
    • .getClassInfo() returns the ClassInfo object for the annotation class.
    • .isInherited() returns true if the annotation is meta-annotated with @Inherited, which means the annotation is inherited by the subclasses of annotated classes.
    • .toStringWithSimpleNames() returns a simpler rendering of the annotation than AnnotationInfo#toString(), by using only the simple name of any referenced classes.
  • Parameters:
    • .getParameterValues() returns the parameter values of this annotation, including any parameter values that were not given explicitly at the annotation use site but that have a default value declared by the annotation type, as an AnnotationParameterValueList of AnnotationParameterValue objects. This is usually the method you want.
    • .getDeclaredParameterValues() returns only the parameter values that were given explicitly at the annotation use site, without filling in any defaults.
    • .getDefaultParameterValues() returns only the default parameter values declared by the annotation class returned by .getClassInfo(). Default parameter values are declared by the annotation class, so if the annotation class was not scanned, the empty list is returned.

AnnotationParameterValue

Holds an annotation parameter name and value.

  • .getName() returns the name of the annotation parameter as a String.
  • .getValue() returns the annotation parameter value as an Object. May be one of the following types:
    • String for string constants, or String[] for arrays of strings
    • A boxed type -- Integer, Long, Short, Boolean, Character, Float, Double or Byte -- for primitive-typed constants
    • A one-dimensional primitive array (int[], long[], short[], char[], byte[], boolean[], float[] or double[]) for arrays of primitives
    • A one-dimensional Object[] array for other array types, where the array element type may be any of the types in this list
    • AnnotationEnumValue for enum constants
    • AnnotationClassRef for Class<?> references within annotations
    • AnnotationInfo for nested annotations

AnnotationParameterValueList

Extends ArrayList<AnnotationParameterValue> with the following convenience methods:

  • .asMap() returns the AnnotationParameterValueList as a Map<String, AnnotationParameterValue> mapping each annotation parameter name to the corresponding AnnotationParameterValue object.
  • .getNames() returns a list of the names of the annotation parameters in this list, as a List<String>.
  • .getAsStrings() returns a list of the result of calling .toString() on each AnnotationParameterValue object in this list, producing a List<String> of String representations of each annotation parameter name and value.
    • .getAsStringsWithSimpleNames() works like .getAsStrings(), but uses only the simple name of any referenced classes, by calling .toStringWithSimpleNames() on each list element rather than .toString().
  • .containsName(String parameterName) returns true if the list contains an annotation parameter of the requested name.
  • .get(String parameterName) returns the AnnotationParameterValue object in this list with the requested parameter name, or null if not found.
  • .getValue(String parameterName) returns the value of the AnnotationParameterValue object in this list with the requested parameter name, by calling AnnotationParameterValue#getValue() on that object, or null if not found.

AnnotationEnumValue

Represents an enum constant in an annotation parameter value. ClassGraph reads the enum class name and the constant name straight from the classfile, so the enum class is never loaded or initialized.

  • .getClassName() returns the name of the enum class as a String.
  • .getValueName() returns the name of the enum constant value as a String.
  • .getName() returns the fully-qualified name of the enum constant value (i.e. getClassName() + "." + getValueName()) as a String.

💡 To get the FieldInfo objects for the constants of an enum class, without loading it, call ClassInfo#getEnumConstants().

AnnotationClassRef

Represents a Class<?> reference in an annotation parameter value. Only the name of the referenced class is read from the classfile -- the class itself is never loaded.

  • .getName() returns the name of the referenced class as a String.
  • .getClassInfo() returns the ClassInfo object for the referenced class, if the referenced class was encountered during scanning (causing a ClassInfo object to be created for it). Returns null if the referenced class was not encountered during scanning, e.g. if it was rejected.

AnnotationInfoList

Extends ArrayList<AnnotationInfo> with the following convenience methods:

  • .asMap() returns the AnnotationInfoList as a Map<String, AnnotationInfo> mapping each annotation name to the corresponding AnnotationInfo object.
  • .directOnly() returns the list of direct annotations, excluding meta-annotations. If this AnnotationInfoList consists of class annotations, i.e. if it was produced by calling ClassInfo#getAllAnnotationInfo(), then the returned list also excludes annotations inherited from a superclass or implemented interface that was annotated with @java.lang.annotation.Inherited. (Calling .getDirectAnnotationInfo() on the annotated element is shorthand for exactly this.)
  • .getNames() returns a list of the names of the annotations in this list, as a List<String>.
  • .getAsStrings() returns a list of the result of calling .toString() on each AnnotationInfo object in this list, producing a List<String> of String representations of each annotation, including annotation parameters, etc.
    • .getAsStringsWithSimpleNames() works like .getAsStrings(), but uses only the simple name of any referenced classes.
  • .containsName(String annotationName) returns true if this list contains an annotation of the requested name.
  • .get(String annotationName) returns the first AnnotationInfo object in this list with the requested name, if present, otherwise returns null. There will only be one annotation in the list with a given name, unless the annotation is a @Repeatable annotation.
  • .getRepeatable(String annotationName | Class<? extends Annotation> annotationClass) returns all AnnotationInfo objects in this list with the requested annotation name or class, as an AnnotationInfoList, otherwise returns the empty list. The returned list will only contain zero or one elements unless the named annotation is @Repeatable.
  • .filter(Predicate<AnnotationInfo> filter) returns an AnnotationInfoList that is a subset of the original list, obtained by applying the given predicate to each AnnotationInfo object in the list, e.g. .filter(AnnotationInfo::isInherited).

Clone this wiki locally