Proposal for JSE API representing java.specification.version
Andrew Guibert
aguibert at us.ibm.com
Wed Nov 2 23:22:56 UTC 2016
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.
Regards, Andy
[1]
https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/JavaVersion.html
More information about the jigsaw-dev
mailing list