System.out.println(characters.get(selected).getName());
// The name printed is "Mario" But the if statement will not
// work as though the two strings are diffrent but they are the same.
if(characters.get(selected).getName() == "Mario"){
playSound("sounds/clickmario.wav");
}
比较两个字符串,当我调试比较时,比较是“Mario”到“Mario”,所以 if 语句应该是真的,但它是假的,因为 if 语句中的任何内容都没有被读取。为什么会这样?我已经尝试将此 .getname 分配给 tempString 并进行比较,但是当它们是相同的字符串时,语句结果为假。请帮忙