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");
}
比较两个字符串相等但不会工作,当我调试比较是“马里奥”到“马里奥”这样的if语句应该是真实的,但它的假,因为没有内部的if语句正在阅读。这是为什么发生?我试着将这个.getname赋值给一个tempString并进行比较,但是当它们是相同的字符串时,语句结果为false。请帮助两个字符串的if语句
谢谢!现在的作品 – user2827416