Elide GraalVM25.6.0-elide.4
All types
Versions and modules

Version

Javaclassin org.graalvm.homesince 19.3

public final class Version implements Comparable<Version>
Inheritance
  1. Object
  2. Version
Implements

A version utility to canonicalize and compare GraalVM versions. The GraalVM version string is not standardized and may change without notice. This class is designed to evolve with GraalVM to cover all used version formats in use. It allows to create, validate and compare GraalVM versions. Do not rely on the format of the raw version string or the result of toString(), only use it to produce output for humans.

To create version instances of a particular version use the create(int...) factory method. Use getCurrent() to lookup the current GraalVM version or parse(String) to parse it from a raw string.

Usage example:

This code example compares the current GraalVM version to be at least 19.3 and fails if it is not.

if (Version.getCurrent().compareTo(19, 3) < 0) {
    throw new IllegalStateException("Invalid GraalVM version. Must be at least 19.3.");
}

Note: this class has a natural ordering that is inconsistent with equals.

Methods12

boolean isRelease()

isRelease

since 19.3
public boolean isRelease()

Returns true if this is a supported release build of GraalVM else false. Use this for implementation assertions that verify that only releases are deployed to production.

Returns

boolean
No description.

See also

boolean isSnapshot()

isSnapshot

since 19.3
public boolean isSnapshot()

Returns true if this is an unsupported snapshot build of GraalVM else false. Use this for implementation assertions that verify that only releases are deployed to production.

Returns

boolean
No description.

See also

int compareTo(Version)Described in compareTo(T).

compareTo

since 19.3
public int compareTo(Version o)

Described in compareTo(T).

Parameters

oVersion
No description.

Returns

int
No description.
int compareTo(int...)

compareTo

since 19.3
public int compareTo(int... compareVersions)

Compares this version to another GraalVM version. This is equivalent to using: compareTo(Version.create(compareVersions)) .

Parameters

compareVersionsint...
No description.

Returns

int
No description.
boolean equals(Object)Described in equals(java.lang.Object).

equals

since 19.3
public boolean equals(Object obj)

Described in equals(java.lang.Object).

Parameters

objObject
No description.

Returns

boolean
No description.
int hashCode()Described in hashCode().

hashCode

since 19.3
public int hashCode()

Described in hashCode().

Returns

int
No description.
String toString()Described in toString().

toString

since 19.3
public String toString()

Described in toString().

Returns

String
No description.
String format(String)

format

since 23.0
public String format(String format)

Format the GraalVM version with a custom format string.

The format string can contain any of the standard conversions of Formatter. At least four version components (possibly zero) are available as formatter arguments.

In addition to the standard conversions, these special conversions are available:

  • "%[R...]" includes a given part only if isRelease

  • "%[S...]" includes a given part only if isSnapshot

  • "%[<digit>...]" includes a given part only if the version contains at least <digit> non-zero version components (<digit> can be 0 to 9)

Examples:
Version.parse("22.3.0.1").format("%d.%d"); // returns "22.3"
Version.parse("22.3.0.1").format("%4$d"); // returns "1"
Version.parse("22.3.0.1").format("%[R%d.%d]%[Sdev]"); // returns "22.3"
Version.parse("22.3.0.1").format("%[2XX]"); // returns "XX"
Version.parse("23.0-dev").format("%3$d"); // returns "0"
Version.parse("23.0-dev").format("%[R%d.%d]%[Sdev]"); // returns "dev"
Version.parse("23.0-dev").format("%[2XX]"); // returns ""

Parameters

formatString
No description.

Returns

String
No description.
int getComponent(int)

getComponent

since 24.2
public int getComponent(int componentIndex)

Retrieves the numeric value of the version component at the specified index.

Version components are indexed as follows:

  • componentIndex = 0 represents the major version

  • componentIndex = 1 represents the minor version

  • componentIndex = 2 represents the update version

If the specified componentIndex exceeds the number of available components, the method returns 0. For example, a version 23.1 will return 0 for componentIndex = 2.

Parameters

componentIndexint
the index of the version component to retrieve; must be non-negative

Returns

int
No description.

Throws

IllegalArgumentExceptionunchecked
if componentIndex is negative
static Version parse(String)

parse

staticsince 19.3
public static Version parse(String versionString) throws IllegalArgumentException

Parses a GraalVM version from its String raw format. Throws IllegalArgumentException if the passed string is not a valid GraalVM version.

Parameters

versionStringString
No description.

Returns

Version
No description.

Throws

static Version create(int...)

create

staticsince 19.3
public static Version create(int... versions) throws IllegalArgumentException

Constructs a new GraalVM version from a list of version numbers. The versions must not be null and none of the version numbers must be negative. At least one version number must be non-zero.

Parameters

versionsint...
No description.

Returns

Version
No description.

Throws

static Version getCurrent()

getCurrent

staticsince 19.3
public static Version getCurrent()

Returns the current GraalVM version of the installed component. Never null.

Returns

Version
No description.

Inherited members