Proposal for JSE API representing java.specification.version
Remi Forax
forax at univ-mlv.fr
Wed Nov 2 23:33:56 UTC 2016
----- Mail original -----
> De: "Andrew Guibert" <aguibert at us.ibm.com>
> À: "jigsaw-dev" <jigsaw-dev at openjdk.java.net>
> Envoyé: Jeudi 3 Novembre 2016 00:22:56
> Objet: Proposal for JSE API representing java.specification.version
> Hello all,
>
> Many Java frameworks and applications require knowledge of the Java version
> they are running on. Currently the only way to check the Java version is
> by doing:
>
> String javaVersion = System.getProperty("java.specification.version");
>
> This of course returns a String, which is very awkward to work with when it
> comes to comparisons. For example, if I want to check if my code is
> running at least on Java 8, I have to do the following:
>
> if (Pattern.matches("1\\.[0-7]", javaVersion))
> // at java 7 or earlier
> else
> // at java 8 or later
>
> It would be nice if the JDK had a built-in enum, similar to what is
> provided by org.apache.commons [1], so that Java version comparisons are
> less awkward.
>
> I'm not familiar with the process is for getting new APIs into the JDK, but
> if it is a simple matter of making a pull request I can certainly do so.
Hi Andrew,
are you aware of Runtime.Version (introduced in 9):
http://download.java.net/java/jdk9/docs/api/java/lang/Runtime.Version.html
>
> Regards, Andy
>
> [1]
> https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/JavaVersion.html
cheers,
Rémi
More information about the jigsaw-dev
mailing list