Enum Class JavaVersion
- All Implemented Interfaces:
Serializable, Comparable<JavaVersion>, Constable
An enumeration of all java versions starting from 8. This list is updated each time an early access build for a new
java version gets released.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionJava version 10.Java version 11 (LTS).Java version 12.Java version 13.Java version 14.Java version 15.Java version 16.Java version 17 (LTS).Java version 18.Java version 19.Java version 20.Java version 21 (LTS).Java version 22.Java version 23.Java version 24.Java version 25 (LTS).Java version 26.Java version 8 (LTS).Java version 9.Represents all java versions after the latest known release in this list.Represents all java version before 8. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final doubleprivate final Stringprivate static final JavaVersion[]private static final JavaVersionprivate final intprivate static final JavaVersion -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateJavaVersion(int majorVersion, double classFileVersion, @NonNull String displayName) Constructs a new java version constant. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if the version of the current java runtime is at least this java version.doubleGet the class file version number of this java version.Get the display name of this java version.static @NonNull Optional<JavaVersion> fromClassFileVersion(double classFileVersion) Finds the java version enum constant that is representing the given class file version.static @NonNull Optional<JavaVersion> fromMajor(int version) Finds the exact known java version from the given major version.static @NonNull JavaVersionguessFromMajor(int major) Guesses the java version from the given major version, returning eitherJAVA_NEXTorJAVA_UNSUPPORTEDin case no known version uses the given major version.booleanisInRange(@NonNull JavaVersion lowerBound, @NonNull JavaVersion upperBound) Checks if this java version is newer or at the given lower bound and older or at the given upper bound.booleanisNewerOrAt(@NonNull JavaVersion version) Checks if this java version is newer or at the given other version.booleanisOlderOrAt(@NonNull JavaVersion version) Checks if this java version is older or at the given other version.intReturns the major version number of this java version.private static @NonNull JavaVersion[]Constructs an array of the java versions that are actually usable in the runtime (this excludes the unsupported and next constants).private static @NonNull JavaVersionResolves the runtime version of the current jvm.static @NonNull JavaVersionGet the java version enum constant representing the current runtime version.booleanChecks if this java version constant is actually supported.static JavaVersionReturns the enum constant of this class with the specified name.static JavaVersion[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
JAVA_UNSUPPORTED
Represents all java version before 8. -
JAVA_NEXT
Represents all java versions after the latest known release in this list. -
JAVA_8
Java version 8 (LTS). -
JAVA_9
Java version 9. -
JAVA_10
Java version 10. -
JAVA_11
Java version 11 (LTS). -
JAVA_12
Java version 12. -
JAVA_13
Java version 13. -
JAVA_14
Java version 14. -
JAVA_15
Java version 15. -
JAVA_16
Java version 16. -
JAVA_17
Java version 17 (LTS). -
JAVA_18
Java version 18. -
JAVA_19
Java version 19. -
JAVA_20
Java version 20. -
JAVA_21
Java version 21 (LTS). -
JAVA_22
Java version 22. -
JAVA_23
Java version 23. -
JAVA_24
Java version 24. -
JAVA_25
Java version 25 (LTS). -
JAVA_26
Java version 26.
-
-
Field Details
-
JAVA_VERSIONS
-
LATEST_VERSION
-
RUNTIME_VERSION
-
majorVersion
private final int majorVersion -
classFileVersion
private final double classFileVersion -
displayName
-
-
Constructor Details
-
JavaVersion
private JavaVersion(int majorVersion, double classFileVersion, @NonNull @NonNull String displayName) Constructs a new java version constant.- Parameters:
majorVersion- the major version number of the release.classFileVersion- the class file version used by the release.displayName- the display name of the release.- Throws:
NullPointerException- if the given display name is null.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
resolveActualJavaVersions
Constructs an array of the java versions that are actually usable in the runtime (this excludes the unsupported and next constants).- Returns:
- an array of the java versions that are actually executable.
-
resolveRuntimeVersion
Resolves the runtime version of the current jvm. This method returnsJAVA_NEXTif the current jvm version is newer than the latest registered version in this enum. On the other hand, this method returnsJAVA_UNSUPPORTEDif the runtime version is older than 8.- Returns:
- the java version enum constant representing the current jvm version.
-
runtimeVersion
Get the java version enum constant representing the current runtime version.- Returns:
- the java version enum constant representing the current runtime version.
-
fromClassFileVersion
Finds the java version enum constant that is representing the given class file version. This method returns an empty optional if no known java version represents that version.- Parameters:
classFileVersion- the class file version to find the java version constant of.- Returns:
- an optional containing the java version that is associated with the given class file version, if any.
-
guessFromMajor
Guesses the java version from the given major version, returning eitherJAVA_NEXTorJAVA_UNSUPPORTEDin case no known version uses the given major version.- Parameters:
major- the major version number of the java version to get.- Returns:
- the exact matching java version from the major version, or either next or unsupported.
-
fromMajor
Finds the exact known java version from the given major version. This method returns an empty optional in case no known java version with the given major version number matches.- Parameters:
version- the major version number of the java version to find.- Returns:
- an optional containing the java version associated with the given major version, if any.
-
majorVersion
public int majorVersion()Returns the major version number of this java version.- Returns:
- the major version number of this java version.
-
classFileVersion
public double classFileVersion()Get the class file version number of this java version.- Returns:
- the class file version number of this java version.
-
displayName
-
supported
public boolean supported()Checks if this java version constant is actually supported. In other words, this method checks if this java version is notJAVA_UNSUPPORTED.- Returns:
- true if this java version constant is actually supported, false otherwise.
-
atOrAbove
public boolean atOrAbove()Checks if the version of the current java runtime is at least this java version.- Returns:
- true if the runtime version is at least this java version, false otherwise.
-
isInRange
public boolean isInRange(@NonNull @NonNull JavaVersion lowerBound, @NonNull @NonNull JavaVersion upperBound) Checks if this java version is newer or at the given lower bound and older or at the given upper bound. There is no sanity check made if the lower bound is smaller than the upper bound.- Parameters:
lowerBound- the lower bound of the version range to check.upperBound- the upper bound of the version range to check.- Returns:
- true if this version is within the lower and upper java version bound, false otherwise.
- Throws:
NullPointerException- if the given lower or upper bound is null.
-
isNewerOrAt
Checks if this java version is newer or at the given other version.- Parameters:
version- the version to check against.- Returns:
- true if this version is newer or at the given version, false otherwise.
- Throws:
NullPointerException- if the given version is null.
-
isOlderOrAt
Checks if this java version is older or at the given other version.- Parameters:
version- the version to check against.- Returns:
- true if this version is older or at the given version, false otherwise.
- Throws:
NullPointerException- if the given version is null.
-