我已经阅读了equals()java中的方法.我听说它仅基于价值进行比较.但是为什么它会在我的情况下返回false,其中值相同但类型不同?
public class test {
public static void main(String[] args)
{
String s1="compare";
StringBuffer s2=new StringBuffer("compare");
System.out.println(s1.equals(s2)); //false
}
}
Run Code Online (Sandbox Code Playgroud)