gpt4 book ai didi

java - java中的string "=="检查引用,为什么这段代码返回true?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:41:38 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
If == compares references in Java, why does it evaluate to true with these Strings?
String comparision with logical operator in Java

public static void main(String[] args) 
{
String a = "ab";
final String bb = "b";
String b = "a" + bb;
System.out.println(a == b);
}

为什么打印为真??

但是,

public static void main(String[] args)
{
String a = "ab";
String bb = "b";
String b = "a" + bb;
System.out.println(a==b);
}

它打印错误。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com