Package net.bytebuddy
Class ClassFileVersion
java.lang.Object
net.bytebuddy.ClassFileVersion
- All Implemented Interfaces:
Serializable
,Comparable<ClassFileVersion>
A wrapper object for representing a validated class file version in the format that is specified by the
JVMS.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface
A locator for the executing VM's Java version. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
Returns the minimal version number that is legal.private static final ClassFileVersion[]
An array of class file versions in their sorting order.static final ClassFileVersion
The class file version of Java 1.static final ClassFileVersion
The class file version of Java 10.static final ClassFileVersion
The class file version of Java 11.static final ClassFileVersion
The class file version of Java 12.static final ClassFileVersion
The class file version of Java 13.static final ClassFileVersion
The class file version of Java 14.static final ClassFileVersion
The class file version of Java 15.static final ClassFileVersion
The class file version of Java 16.static final ClassFileVersion
The class file version of Java 17.static final ClassFileVersion
The class file version of Java 18.static final ClassFileVersion
The class file version of Java 19.static final ClassFileVersion
The class file version of Java 2.static final ClassFileVersion
The class file version of Java 20.static final ClassFileVersion
The class file version of Java 21.static final ClassFileVersion
The class file version of Java 22.static final ClassFileVersion
The class file version of Java 23.static final ClassFileVersion
The class file version of Java 24.static final ClassFileVersion
The class file version of Java 3.static final ClassFileVersion
The class file version of Java 4.static final ClassFileVersion
The class file version of Java 5.static final ClassFileVersion
The class file version of Java 6.static final ClassFileVersion
The class file version of Java 7.static final ClassFileVersion
The class file version of Java 8.static final ClassFileVersion
The class file version of Java 9.private static final long
The class's serial version UID.private static final ClassFileVersion.VersionLocator
A version locator for the executing JVM.private final int
The version number that is represented by this class file version instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ClassFileVersion
(int versionNumber) Creates a wrapper for a given minor-major release of the Java class file format. -
Method Summary
Modifier and TypeMethodDescriptionReturns this class file version indicating a class using preview features.int
compareTo
(ClassFileVersion other) private static <T> T
doPrivileged
(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.boolean
int
Returns the Java runtime version number of this class file version.short
Returns the major version this instance represents.int
Returns the minor-major release number of this class file version.short
Returns the minor version this instance represents.int
hashCode()
boolean
isAtLeast
(ClassFileVersion classFileVersion) Checks if this class file version is at least as new as the provided version.boolean
isAtMost
(ClassFileVersion classFileVersion) Checks if this class file version is at most as new as the provided version.boolean
isGreaterThan
(ClassFileVersion classFileVersion) Checks if this class file version is newer than the provided version.boolean
isLessThan
(ClassFileVersion classFileVersion) Checks if this class file version is older than the provided version.boolean
Returnstrue
if this class file version indicates the use of preview features.static ClassFileVersion
latest()
Returns the latest officially supported Java version when experimental support is not enabled.static ClassFileVersion
Extracts a class' class version.static ClassFileVersion
of
(Class<?> type, ClassFileLocator classFileLocator) Extracts a class' class version.static ClassFileVersion
of
(TypeDescription typeDescription, ClassFileLocator classFileLocator) Extracts a class' class version.static ClassFileVersion
ofClassFile
(byte[] binaryRepresentation) Extracts a class' class version from a class file.static ClassFileVersion
ofJavaVersion
(int javaVersion) Creates a class file version for a given major release of Java.static ClassFileVersion
ofJavaVersionString
(String javaVersionString) Returns the Java class file by its representation by a version string in accordance to the formats known to javac.static ClassFileVersion
ofMinorMajor
(int versionNumber) Creates a wrapper for a given minor-major release of the Java class file format.static ClassFileVersion
ofThisVm()
Finds the highest class file version that is compatible to the current JVM version.static ClassFileVersion
ofThisVm
(ClassFileVersion fallback) Finds the highest class file version that is compatible to the current JVM version.toString()
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDThe class's serial version UID.- See Also:
-
BASE_VERSION
protected static final int BASE_VERSIONReturns the minimal version number that is legal.- See Also:
-
JAVA_V1
The class file version of Java 1. -
JAVA_V2
The class file version of Java 2. -
JAVA_V3
The class file version of Java 3. -
JAVA_V4
The class file version of Java 4. -
JAVA_V5
The class file version of Java 5. -
JAVA_V6
The class file version of Java 6. -
JAVA_V7
The class file version of Java 7. -
JAVA_V8
The class file version of Java 8. -
JAVA_V9
The class file version of Java 9. -
JAVA_V10
The class file version of Java 10. -
JAVA_V11
The class file version of Java 11. -
JAVA_V12
The class file version of Java 12. -
JAVA_V13
The class file version of Java 13. -
JAVA_V14
The class file version of Java 14. -
JAVA_V15
The class file version of Java 15. -
JAVA_V16
The class file version of Java 16. -
JAVA_V17
The class file version of Java 17. -
JAVA_V18
The class file version of Java 18. -
JAVA_V19
The class file version of Java 19. -
JAVA_V20
The class file version of Java 20. -
JAVA_V21
The class file version of Java 21. -
JAVA_V22
The class file version of Java 22. -
JAVA_V23
The class file version of Java 23. -
JAVA_V24
The class file version of Java 24. -
CLASS_FILE_VERSIONS
An array of class file versions in their sorting order. -
VERSION_LOCATOR
A version locator for the executing JVM. -
versionNumber
private final int versionNumberThe version number that is represented by this class file version instance.
-
-
Constructor Details
-
ClassFileVersion
protected ClassFileVersion(int versionNumber) Creates a wrapper for a given minor-major release of the Java class file format.- Parameters:
versionNumber
- The minor-major release number.
-
-
Method Details
-
doPrivileged
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.- Type Parameters:
T
- The type of the action's resolved value.- Parameters:
action
- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
ofMinorMajor
Creates a wrapper for a given minor-major release of the Java class file format.- Parameters:
versionNumber
- The minor-major release number.- Returns:
- A representation of the version number.
-
ofJavaVersionString
Returns the Java class file by its representation by a version string in accordance to the formats known to javac.- Parameters:
javaVersionString
- The Java version string.- Returns:
- The appropriate class file version.
-
ofJavaVersion
Creates a class file version for a given major release of Java. Currently, all versions reaching from Java 1 to Java 9 are supported.- Parameters:
javaVersion
- The Java version.- Returns:
- A wrapper for the given Java class file version.
-
latest
Returns the latest officially supported Java version when experimental support is not enabled.- Returns:
- The latest officially supported Java version.
-
ofThisVm
Finds the highest class file version that is compatible to the current JVM version. Prior to Java 9, this is achieved by parsing thejava.version
property which is provided bySystem.getProperty(String)
. If the system property is not available, anIllegalStateException
is thrown.- Returns:
- The currently running Java process's class file version.
-
ofThisVm
Finds the highest class file version that is compatible to the current JVM version. Prior to Java 9, this is achieved by parsing thejava.version
property which is provided bySystem.getProperty(String)
. If the system property is not available, thefallback
version is returned.- Parameters:
fallback
- The version to fall back to if locating a class file version is not possible.- Returns:
- The currently running Java process's class file version or the fallback if locating this version is impossible.
-
of
Extracts a class' class version. The class' byte code is located by querying theClassLoader
of the class.- Parameters:
type
- The type for which to locate a class file version.- Returns:
- The type's class file version.
- Throws:
IOException
- If an error occurs while reading the class file.
-
of
public static ClassFileVersion of(Class<?> type, ClassFileLocator classFileLocator) throws IOException Extracts a class' class version.- Parameters:
type
- The type for which to locate a class file version.classFileLocator
- The class file locator to query for a class file.- Returns:
- The type's class file version.
- Throws:
IOException
- If an error occurs while reading the class file.
-
of
public static ClassFileVersion of(TypeDescription typeDescription, ClassFileLocator classFileLocator) throws IOException Extracts a class' class version.- Parameters:
typeDescription
- The type for which to locate a class file version.classFileLocator
- The class file locator to query for a class file.- Returns:
- The type's class file version.
- Throws:
IOException
- If an error occurs while reading the class file.
-
ofClassFile
Extracts a class' class version from a class file.- Parameters:
binaryRepresentation
- The class file's binary representation.- Returns:
- The supplied class file's class file version.
-
getMinorMajorVersion
public int getMinorMajorVersion()Returns the minor-major release number of this class file version.- Returns:
- The minor-major release number of this class file version.
-
getMajorVersion
public short getMajorVersion()Returns the major version this instance represents.- Returns:
- The major version this instance represents.
-
getMinorVersion
public short getMinorVersion()Returns the minor version this instance represents.- Returns:
- The minor version this instance represents.
-
getJavaVersion
public int getJavaVersion()Returns the Java runtime version number of this class file version.- Returns:
- The Java runtime version.
-
isAtLeast
Checks if this class file version is at least as new as the provided version.- Parameters:
classFileVersion
- The version to check against.- Returns:
true
if this version is at least of the given version.
-
isGreaterThan
Checks if this class file version is newer than the provided version.- Parameters:
classFileVersion
- The version to check against.- Returns:
true
if this version is newer than the provided version.
-
isAtMost
Checks if this class file version is at most as new as the provided version.- Parameters:
classFileVersion
- The version to check against.- Returns:
true
if this version is as most as new as the provided version.
-
isLessThan
Checks if this class file version is older than the provided version.- Parameters:
classFileVersion
- The version to check against.- Returns:
true
if this version is older than the provided version.
-
asPreviewVersion
Returns this class file version indicating a class using preview features.- Returns:
- This class file version but indicating the use of preview features.
-
isPreviewVersion
public boolean isPreviewVersion()Returnstrue
if this class file version indicates the use of preview features.- Returns:
true
if this class file version indicates the use of preview features.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ClassFileVersion>
-
hashCode
public int hashCode() -
equals
-
toString
-