我正在尝试比较一个字符串和一个字符(在将其转换为字符串之后)。代码没有像我期望的那样工作。
package main;
import java.lang.Character;
public class Main {
public static void main(String[] args) {
char myChar = 'a';
String myString = "a";
if(myString == Character.toString(myChar)) {
System.out.println("This SHOULD work! But it doesn't.");
} else {
System.out.println("This SHOULDN'T work! But it does.");
}
}
}
我在这里做错了什么?