ClassModel (Java SE 23 & JDK 23)
Description: declaration: module: java.base, package: java.lang.classfile, interface: ClassModel
Keywords: java.lang.classfile.ClassModel interface

# Interface ClassModel

All Superinterfaces:
  `AttributedElementPREVIEW`, `ClassFileElementPREVIEW`, `CompoundElementPREVIEW<ClassElementPREVIEW>`, `Iterable<ClassElementPREVIEW>`

public sealed interface ClassModel extends CompoundElementPREVIEW<ClassElementPREVIEW>, AttributedElementPREVIEW
`ClassModel` is a preview API of the Java platform.
Programs can only use `ClassModel` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Models a classfile. The contents of the classfile can be traversed via a streaming view (e.g., `CompoundElement.elements()`PREVIEW), or via random access (e.g., `flags()`), or by freely mixing the two.

Since:
  22

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ConstantPoolPREVIEW`
  `constantPool()`
  Returns the constant pool for this class.
  `List<FieldModelPREVIEW>`
  `fields()`
  Returns the fields of this class.
  `AccessFlagsPREVIEW`
  `flags()`
  Returns the access flags.
  `List<ClassEntryPREVIEW>`
  `interfaces()`
  Returns the interfaces implemented by this class.
  `boolean`
  `isModuleInfo()`
  Returns whether this class is a module descriptor.
  `int`
  `majorVersion()`
  Returns the major classfile version.
  `List<MethodModelPREVIEW>`
  `methods()`
  Returns the methods of this class.
  `int`
  `minorVersion()`
  Returns the minor classfile version.
  `Optional<ClassEntryPREVIEW>`
  `superclass()`
  Returns the superclass of this class, if there is one.
  `ClassEntryPREVIEW`
  `thisClass()`
  Returns the constant pool entry describing the name of this class.

  ### Methods declared in interface java.lang.classfile.AttributedElementPREVIEW

  `attributes, findAttribute, findAttributes`

  ### Methods declared in interface java.lang.classfile.CompoundElementPREVIEW

  `elementList, elements, elementStream, forEachElement, iterator`

  ### Methods declared in interface java.lang.Iterable

  `forEach, spliterator`

- ## Method Details

  - ### constantPool

    ConstantPoolPREVIEW constantPool()
    Returns the constant pool for this class.
    Returns:
      the constant pool for this class

  - ### flags

    AccessFlagsPREVIEW flags()
    Returns the access flags.
    Returns:
      the access flags

  - ### thisClass

    ClassEntryPREVIEW thisClass()
    Returns the constant pool entry describing the name of this class.
    Returns:
      the constant pool entry describing the name of this class

  - ### majorVersion

    int majorVersion()
    Returns the major classfile version.
    Returns:
      the major classfile version

  - ### minorVersion

    int minorVersion()
    Returns the minor classfile version.
    Returns:
      the minor classfile version

  - ### fields

    List<FieldModelPREVIEW> fields()
    Returns the fields of this class.
    Returns:
      the fields of this class

  - ### methods

    List<MethodModelPREVIEW> methods()
    Returns the methods of this class.
    Returns:
      the methods of this class

  - ### superclass

    Optional<ClassEntryPREVIEW> superclass()
    Returns the superclass of this class, if there is one.
    Returns:
      the superclass of this class, if there is one

  - ### interfaces

    List<ClassEntryPREVIEW> interfaces()
    Returns the interfaces implemented by this class.
    Returns:
      the interfaces implemented by this class

  - ### isModuleInfo

    boolean isModuleInfo()
    Returns whether this class is a module descriptor.
    Returns:
      whether this class is a module descriptor