import java.util.Objects; //导入方法依赖的package包/类
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}