How to use code to determine whether the current system supports a certain version of feature
How to use the code to judge whether the current system supports a certain version of feature, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
JDK9 has been out for some time, so many popular Java applications have added support for JDK9 and even JDK10, such as Tomcat.
We download the latest Tomcat source package from this link, with a total of 7MB:
Https://tomcat.apache.org/download-90.cgi
After unzipping, find the file JreMemoryLeakPreventionListener.java in the folder apache-tomcat-9.0.10-srcjavaorgapachecatalinacore:
You can see a large number of calls to the utility class JreCompat to see if JRE9 is available:
JreCompat.isJre9Available ()
View the specific implementation of isJre9Available:
Public static boolean isJre9Available () {return jre9Available;}
Controlled by a boolean: jre9Available.
The boolean of jre9Available is controlled by Jre9Compat.isSupported (): static {/ / This is Tomcat 9 with a minimum Java version of Java 8. / / Look for the highest supported JVM first if (Jre9Compat.isSupported ()) {instance = new Jre9Compat (); jre9Available = true;} else {instance = new JreCompat (); jre9Available = false;}}
Then look at the code of Jre9Compat.isSupported ():
Static boolean isSupported () {return inaccessibleObjectExceptionClazz! = null;}
Once inaccessibleObjectExceptionClazz is not null, JRE9 is available.
InaccessibleObjectExceptionClazz is from Class.forName ("java.lang.reflect.InaccessibleObjectException")
The class java.lang.reflect.InaccessibleObjectException was just introduced by Java 9. So if you can't load this class with Class loader, it must indicate that the current running environment is below Java 9.
The detection of the Java runtime environment in this way is more accurate than System.getProperty, because the information obtained by the latter may theoretically be overwritten by others with setProperty.
ABAP
View the version information of Software component through the table CVERS:
After reading the above, do you know how to use code to determine whether the current system supports a certain version of feature? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!