Interface ClassInfo

All Superinterfaces:
AnnotationTarget, DeclarationInfo

public interface ClassInfo extends DeclarationInfo
A class. Five kinds of classes are distinguished:
  • plain classes
  • interfaces
  • enums (restricted kind of classes)
  • annotations (specialized kind of interfaces)
  • records (restricted kind of classes)
Classes are represented as isolated units. That is, if this class is nested, it is not possible to obtain the enclosing class. Similarly, it is not possible to obtain the set of classes nested in this class.

At the same time, it is possible to obtain the set of constructors, methods and fields declared in this class, as well as the set of record components if this class is a record. It is also possible to obtain the package this class is declared in.

Since:
4.0
  • Method Details

    • name

      String name()
      Returns the binary name of this class, as defined by The Java™ Language Specification; in other words, the class name as returned by Class.getName().
      Returns:
      binary name of this class, never null
    • simpleName

      String simpleName()
      Returns the simple name of this class, as defined by The Java™ Language Specification; in other words, the class name as returned by Class.getSimpleName().
      Returns:
      simple name of this class, never null
    • packageInfo

      PackageInfo packageInfo()
      Returns the package this class is part of. Returns null if this class is part of an unnamed package.
      Returns:
      this class's package, or null if this class is in an unnamed package
    • typeParameters

      List<TypeVariable> typeParameters()
      Returns a list of type parameters declared on this class. Returns an empty list if this class is not generic and so does not declare type parameters.
      Returns:
      immutable list of this class's type parameters, never null
    • superClass

      Type superClass()
      Returns the type of this class's superclass. Returns null if this class does not have a superclass; that is, if this class is java.lang.Object or an interface.
      Returns:
      the type of this class's superclass, or null if there's no superclass
    • superClassDeclaration

      ClassInfo superClassDeclaration()
      Returns the declaration of this class's superclass. Returns null if this class does not have a superclass; that is, if this class is java.lang.Object or an interface.
      Returns:
      the declaration of this class's superclass, or null if there's no superclass
    • superInterfaces

      List<Type> superInterfaces()
      Returns a list of types of this class's direct superinterfaces. Returns an empty list if this class has no direct superinterface.
      Returns:
      immutable list of types of this class's direct superinterfaces, never null
    • superInterfacesDeclarations

      List<ClassInfo> superInterfacesDeclarations()
      Returns a list of declarations of this class's direct superinterfaces. Returns an empty list if this class has no direct superinterface.
      Returns:
      immutable list of declarations of this class's direct superinterfaces, never null
    • isPlainClass

      boolean isPlainClass()
      Returns whether this class is a plain class. That is, not an interface, not an enum, not an annotation, and not a record.
      Returns:
      whether this class is a plain class
    • isInterface

      boolean isInterface()
      Returns whether this class is an interface. If this class is an annotation, returns false.
      Returns:
      whether this class is an interface
    • isEnum

      boolean isEnum()
      Returns whether this class is an enum.
      Returns:
      whether this class is an enum
    • isAnnotation

      boolean isAnnotation()
      Returns whether this class is an annotation.
      Returns:
      whether this class is an annotation
    • isRecord

      boolean isRecord()
      Returns whether this class is a record.
      Returns:
      whether this class is a record
    • isAbstract

      boolean isAbstract()
      Returns whether this class is abstract.

      A plain class is abstract if declared abstract. An enum is abstract if it declares abstract methods. An interface or an annotation is always abstract. A record is never abstract.

      Returns:
      whether this class is abstract
    • isFinal

      boolean isFinal()
      Returns whether this class is final.
      Returns:
      whether this class is final
    • modifiers

      int modifiers()
      Returns the modifiers of this class as an int. Use Modifier to inspect the value.
      Returns:
      the modifiers of this class
    • constructors

      Collection<MethodInfo> constructors()
      Returns a collection of constructors declared or implicitly declared in this class. Constructors declared in direct or indirect superclasses are not included.

      If this class is an interface or an annotation, returns an empty collection.

      Returns:
      immutable collection of constructors, never null
    • methods

      Returns a collection of methods declared or implicitly declared in this class and all its superclasses up to and excluding java.lang.Object, as well as all direct and indirect superinterfaces. If this class is an interface, only superinterfaces are considered. Methods implicitly declared in interfaces are omitted.

      If the collection of methods described above contains multiple methods with the same signature, all such methods are returned. MethodInfo.declaringClass should be used to distinguish such methods.

      Iteration order of the resulting collection is not defined and does not have to correspond to the inheritance hierarchy of this class.

      Returns:
      immutable collection of methods, never null
    • fields

      Returns a collection of fields declared or implicitly declared in this class and all its superclasses up to and excluding java.lang.Object, as well as all direct and indirect superinterfaces. If this class is an interface, only superinterfaces are considered.

      If the collection of fields described above contains multiple fields with the same name, all such fields are returned. FieldInfo.declaringClass should be used to distinguish such fields

      Iteration order of the resulting collection is not defined and does not have to correspond to the inheritance hierarchy of this class.

      Returns:
      immutable collection of fields, never null
    • recordComponents

      Collection<RecordComponentInfo> recordComponents()
      Returns a collection of record components declared in this class. If this class is not a record, returns an empty collection.
      Returns:
      immutable collection of record components, never nul
    • kind

      default DeclarationInfo.Kind kind()
      Description copied from interface: DeclarationInfo
      Returns the kind of this declaration.
      Specified by:
      kind in interface DeclarationInfo
      Returns:
      the kind of this declaration
    • asClass

      default ClassInfo asClass()
      Description copied from interface: DeclarationInfo
      Returns this declaration as a class.
      Specified by:
      asClass in interface DeclarationInfo
      Returns:
      this class, never null