AttributedElement, ClassFileElement, CompoundElement<ClassElement>, Iterable<ClassElement>public sealed interface ClassModel extends CompoundElement<ClassElement>, AttributedElement
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.
ClassFile Structure| Modifier and Type | Method | Description |
|---|---|---|
ConstantPool |
constantPool() |
Returns the constant pool for this class. |
List |
fields() |
Returns the fields of this class. |
AccessFlags |
flags() |
Returns the access flags. |
List |
interfaces() |
Returns the interfaces implemented by this class. |
boolean |
isModuleInfo() |
Returns whether this class file is a module descriptor. |
int |
majorVersion() |
Returns the major version of this class. |
List |
methods() |
Returns the methods of this class. |
int |
minorVersion() |
Returns the minor version of this class. |
Optional |
superclass() |
Returns the superclass of this class, if there is one. |
ClassEntry |
thisClass() |
Returns the constant pool entry describing the name of this class. |
attributes, findAttribute, findAttributes
elementList, elementStream, forEach, iterator, toDebugString
spliterator
ConstantPool constantPool()
AccessFlags flags()
ClassEntry thisClass()
int majorVersion()
[0, 65535].int minorVersion()
[0, 65535].List<FieldModel> fields()
List<MethodModel> methods()
Optional<ClassEntry> superclass()
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.List<ClassEntry> interfaces()
boolean isModuleInfo()
class file is a module descriptor.class file is a module descriptor
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/ClassModel.html