本文介绍了在运行时获取 Java 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要解决 JDK 1.5 中的 Java 错误,该错误已在 1.6 中修复.我正在使用以下条件:
I need to work around a Java bug in JDK 1.5 which was fixed in 1.6. I'm using the following condition:
if (System.getProperty("java.version").startsWith("1.5.")) {
...
} else {
...
}
这是否适用于其他 JVM?有没有更好的方法来检查这个?
Will this work for other JVMs? Is there a better way to check this?
推荐答案
这些文章似乎建议检查 1.5
或 1.6
前缀应该有效,因为它遵循正确版本命名约定.
These articles seem to suggest that checking for 1.5
or 1.6
prefix should work, as it follows proper version naming convention.
- J2SE SDK/JRE 版本字符串命名约定
- 1.5.0 版还是 5.0 版?
- J2SE 还在某些仅对开发人员可见的地方,或在程序解析版本号的地方,保留了版本号 1.5.0(或 1.5)"
- "
java.version
系统属性"
- J2SE SDK/JRE Version String Naming Convention
- Version 1.5.0 or 5.0?
- "J2SE also keeps the version number 1.5.0 (or 1.5) in some places that are visible only to developers, or where the version number is parsed by programs"
- "
java.version
system property"
- Java SE 将版本号 1.6.0(或 1.6)保存在一些只有开发人员可见的地方,或者版本号由程序解析的地方."
- "
java.version
系统属性"
- "Java SE keeps the version number 1.6.0 (or 1.6) in some places that are visible only to developers, or where the version number is parsed by programs."
- "
java.version
system property"
这篇关于在运行时获取 Java 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- "
- "
- "
- "J2SE also keeps the version number 1.5.0 (or 1.5) in some places that are visible only to developers, or where the version number is parsed by programs"
- "
- J2SE 还在某些仅对开发人员可见的地方,或在程序解析版本号的地方,保留了版本号 1.5.0(或 1.5)"