equals
并==
返回false
文本块字符串,尽管它们在控制台中打印相同。
public class Example {
public static void main(String[] args) {
String jsonLiteral = ""
+ "{\n"
+ "\tgreeting: \"Hello\",\n"
+ "\taudience: \"World\",\n"
+ "\tpunctuation: \"!\"\n"
+ "}\n";
String jsonBlock = """
{
greeting: "Hello",
audience: "World",
punctuation: "!"
}
""";
System.out.println(jsonLiteral.equals(jsonBlock)); //false
System.out.println(jsonBlock == jsonLiteral);
}
}
我错过了什么?