对于以下代码:
String bis = "good";
String cis ="good";
char[] ch = {'g','o','o','d'};
String temp="";
for (char c:ch){
temp=temp+c;
}
System.out.println(temp);
System.out.println(cis==bis); //true
System.out.println(bis==temp); //false
“temp”变量评估为“好”,与“bis”和“cis”相同,但 bis==temp 返回 false,而 bis==cis 评估为 true。请告诉我为什么会发生这种情况?在字符串池中存在“好”对象。因此,理想情况下,“临时”引用应该像 bis 和 cis 那样正确指向它?