我刚开始学习 Java,遇到了 equals。在寻找equals和==之间的区别之后,我决定自己练习,但我没有得到预期的结果。这是代码:
public class Sandbox {
/**
* @param args
*
*/
private int a;
public void setAtta(int value){a=value;}
public int getAtta(){return a;}
public static void main(String[] args) {
// TODO Auto-generated method stub
Sandbox s = new Sandbox();
s.setAtta(10);
Sandbox s1 = new Sandbox();
s1.setAtta(10);
System.out.println(s==s1);//false- EXPECTED
System.out.println(s.equals(s1));//false- I thought it should be true?
}
}