APIdia Launch Partner
Top Description Methods
java.lang.classfile

public sealed Interface ClassFileVersion

extends ClassElement
permits ClassFileVersionImpl
Known Direct Implementers
jdk.internal.classfile.impl.ClassFileVersionImpl
Imports
java.lang.reflect.ClassFileFormatVersion, jdk.internal.classfile.impl.ClassFileVersionImpl

Models the minor and major version numbers of a class file (JVMS 4.1). The class file version appears exactly once in each class, and is set to an unspecified default value if not explicitly provided.

The major versions of class file format begins at 45 for Java Platform version 1.0.2, and is continuous up to ClassFile#latestMajorVersion(). In general, each major version defines a new supported class file format, modeled by ClassFileFormatVersion, and supports all previous formats.

For major versions up to 55 for Java SE Platform 11, the minor version of any value is supported. For major versions 56 for Java SE Platform version 12 and above, the minor version must be 0 or 65535. The minor version 0 is always supported, and represents the format modeled by ClassFileFormatVersion. The minor version 65535 indicates the class file uses preview features of the Java SE Platform release represented by the major version. A Java Virtual Machine can only load such a class file if it has the same Java SE Platform version and the JVM has preview features enabled.

Since
24
Java Virtual Machine Specification
4.1 The ClassFile Structure
See Also
ClassModel#majorVersion(), ClassModel#minorVersion(), ClassFileFormatVersion

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the major version
majorVersion
()

Returns the major version.

public int

Returns:

the minor version
minorVersion
()

Returns the minor version.

public static ClassFileVersion

Returns:

a ClassFileVersion element
of
(int
the major version
majorVersion
,
int
the minor version
minorVersion
)

Returns a ClassFileVersion element.

Method Detail

majorVersionback to summary
public int majorVersion()

Returns the major version. It is a u2 value.

API Note

Constants in ClassFile named Java_#_VERSION, where # is a release number, such as ClassFile#JAVA_21_VERSION, describe the class major versions of the Java Platform SE.

Returns:int

the major version

minorVersionback to summary
public int minorVersion()

Returns the minor version. It is a u2 value.

Returns:int

the minor version

ofback to summary
public static ClassFileVersion of(int majorVersion, int minorVersion)

Returns a ClassFileVersion element. The minor version number may be -1 to represent 65535.

Parameters
majorVersion:int

the major version

minorVersion:int

the minor version

Returns:ClassFileVersion

a ClassFileVersion element

Exceptions
IllegalArgumentException:
if the major version or the minor version is not u2; the minor version may be -1