Runtime Version Parse Feature And Build

Break a version string apart with Runtime.Version.parse: feature, interim, update and patch come back as ints while pre, build and optional arrive as Optionals.

JavaCli Tooling

Code

snippet
public class VersionInspector {

    static void describe(String tag, Runtime.Version v) {
        System.out.println(tag + " raw: " + v);
        System.out.println("  version(): " + v.version());
        System.out.println("  feature:   " + v.feature());
        System.out.println("  interim:   " + v.interim());
        System.out.println("  update:    " + v.update());
        System.out.println("  patch:     " + v.patch());
        System.out.println("  pre:       " + v.pre());
        System.out.println("  build:     " + v.build());
        System.out.println("  optional:  " + v.optional());
    }

    public static void main(String[] args) {
        // 语法 $VNUM(+$BUILD(-$OPT)?):21.0.5 + build 9 + 可选信息 LTS
        describe("lts", Runtime.Version.parse("21.0.5+9-LTS"));
        System.out.println();

        // 无 build 的预发布串:pre 有值,build 是空 Optional
        describe("ea", Runtime.Version.parse("20-ea"));

        System.out.println();
        Runtime.Version running = Runtime.version();
        System.out.println("running jvm feature: " + running.feature());
    }
}

What the code does

Runtime Version Parse Feature And Build is built around the class VersionInspector and the functions describe and main.

Watch out for

  • The project needs no additions before running it.

Using it

Signature: static void describe(String tag, Runtime.Version v)

The run emits 9 labeled sections — version():, feature:, interim:, update:, patch:, pre:, build:, optional:, running jvm feature: — one per step.

Execute the file and main walks through describe, in that order.

The key statements, annotated

describe("lts", Runtime.Version.parse("21.0.5+9-LTS"));
describe("ea", Runtime.Version.parse("20-ea"));
Runtime.Version running = Runtime.version();

Interactive Tools for This Topic

FAQ

What does Runtime Version Parse Feature And Build print when run?
Execute the whole file; each printed line is prefixed with a label like `version():`, `feature:`, `interim:`.