APIdia Launch Partner
Top Description Methods
java.lang.classfile

public sealed Interface ClassModel

extends CompoundElement<ClassElement>, AttributedElement
permits ClassImpl
Known Direct Implementers
jdk.internal.classfile.impl.ClassImpl
Imports
java.lang.classfile.attribute.BootstrapMethodsAttribute, .ModuleAttribute, java.lang.classfile.constantpool.ClassEntry, .ConstantPool, .ConstantPoolBuilder, java.lang.constant.ClassDesc, java.lang.reflect.AccessFlag, java.util.List, .Optional, java.util.function.Consumer, jdk.internal.classfile.impl.ClassImpl

Models a class file. A class file can be viewed as a composition of ClassElements, or by random access via accessor methods if only specific parts of the class file is needed.

Use ClassFile#parse(byte[]), which parses the binary data of a class file into a model, to obtain a ClassModel.

To construct a class file, use ClassFile#build(ClassDesc, Consumer). ClassFile#transformClass(ClassModel, ClassTransform) allows creating a new class by selectively processing the original class elements and directing the results to a class builder.

A class holds attributes, most of which are accessible as member elements. BootstrapMethodsAttribute can only be accessed via explicit attribute reading, as it is modeled as part of the constant pool.

Since
24
Java Virtual Machine Specification
4.1 The ClassFile Structure
See Also
ClassFile#parse(byte[]), ClassTransform

Method Summary

Modifier and TypeMethod and Description
public ConstantPool

Returns:

the constant pool for this class
constantPool
()

Returns the constant pool for this class.

public List<FieldModel>

Returns:

the fields of this class
fields
()

Returns the fields of this class.

public AccessFlags

Returns:

the access flags
flags
()

Returns the access flags.

public List<ClassEntry>

Returns:

the interfaces implemented by this class
interfaces
()

Returns the interfaces implemented by this class.

public boolean

Returns:

whether this class file is a module descriptor
isModuleInfo
()

Returns whether this class file is a module descriptor.

public int

Returns:

the major version of this class
majorVersion
()

Returns the major version of this class.

public List<MethodModel>

Returns:

the methods of this class
methods
()

Returns the methods of this class.

public int

Returns:

the minor version of this class
minorVersion
()

Returns the minor version of this class.

public Optional<ClassEntry>

Returns:

the superclass of this class, if there is one
superclass
()

Returns the superclass of this class, if there is one.

public ClassEntry

Returns:

the constant pool entry describing the name of this class
thisClass
()

Returns the constant pool entry describing the name of this class.

Inherited from java.lang.classfile.AttributedElement:
attributesfindAttributefindAttributes
Inherited from java.lang.classfile.CompoundElement:
elementListelementStreamforEachiteratortoDebugString

Method Detail

constantPoolback to summary
public ConstantPool constantPool()

Returns the constant pool for this class.

Returns:ConstantPool

the constant pool for this class

See Also
ConstantPoolBuilder#of(ClassModel)
fieldsback to summary
public List<FieldModel> fields()

Returns the fields of this class.

Returns:List<FieldModel>

the fields of this class

flagsback to summary
public AccessFlags flags()

Returns the access flags.

Returns:AccessFlags

the access flags

See Also
AccessFlag.Location#CLASS
interfacesback to summary
public List<ClassEntry> interfaces()

Returns the interfaces implemented by this class.

Returns:List<ClassEntry>

the interfaces implemented by this class

See Also
Interfaces
isModuleInfoback to summary
public boolean isModuleInfo()

Returns whether this class file is a module descriptor.

Returns:boolean

whether this class file is a module descriptor

See Also
ClassFile#buildModule(ModuleAttribute, Consumer)
majorVersionback to summary
public int majorVersion()

Returns the major version of this class. It is a u2 value.

Returns:int

the major version of this class

See Also
ClassFileVersion
methodsback to summary
public List<MethodModel> methods()

Returns the methods of this class.

Returns:List<MethodModel>

the methods of this class

minorVersionback to summary
public int minorVersion()

Returns the minor version of this class. It is a u2 value.

Returns:int

the minor version of this class

See Also
ClassFileVersion
superclassback to summary
public Optional<ClassEntry> superclass()

Returns the superclass of this class, if there is one. This class file may have no superclass if this represents a module descriptor or the Object class; otherwise, it must have a superclass. If this is an interface, the superclass must be Object.

Returns:Optional<ClassEntry>

the superclass of this class, if there is one

See Also
Superclass
thisClassback to summary
public ClassEntry thisClass()

Returns the constant pool entry describing the name of this class.

Returns:ClassEntry

the constant pool entry describing the name of this class