由于Java代码可以在任何Java VM中运行的事实,我想知道如何以编程方式标识所支持的Unicode版本?
最佳答案
如果您正在寻找一个可以使您获得此信息的类(class),那么这并非易事。
通常,Java支持的Unicode版本从一个主要规范变为另一个主要规范,并且此信息记录在Java API文档的Character类中(从Java语言规范派生)。但是,您不能依赖Java语言规范,因为每个major version of Java need not have its own version of the Java Language Specification都可以。
因此,您应该在JVM支持的Java版本和受支持的Unicode版本之间进行音译:
String specVersion = System.getProperty("java.specification.version");
if(specVersion.equals("1.7"))
return "6.0";
else if(specVersion.equals("1.6"))
return "4.0";
else if(specVersion.equals("1.5"))
return "4.0";
else if(specVersion.equals("1.4"))
return "3.0";
... and so on
可以从Java语言规范中获取受支持版本的详细信息。引用JSR 901(它是Java 7的语言规范):
The Java SE platform tracks the Unicode specification as it evolves. The precise version of Unicode used by a given release is specified in the documentation of the class Character.
Versions of the Java programming language prior to 1.1 used Unicode version 1.1.5. Upgrades to newer versions of the Unicode Standard occurred in JDK 1.1 (to Unicode 2.0), JDK 1.1.7 (to Unicode 2.1), Java SE 1.4 (to Unicode 3.0), and Java SE 5.0 (to Unicode 4.0).
关于unicode - 如何在Java中以编程方式识别支持哪个Unicode版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6941229/