log.info(new String(new byte[]{-7, 'a'}, "UTF-8").length());
Oracle Java 1.8.0_60 导致打印输出为“2”,1.7.0_79 为“1”。
?
最佳答案
您传递的是无效的 UTF-8 序列。来自docs
The behavior of this constructor when the given bytes are not valid in the given charset is unspecified.
因此在正确的实现中,返回的字符串也可能是 "Hello world!"
。
关于unicode - Java 8 处理与 Java 7 不同的无效 UTF-8 编码....?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32512359/