Using the equals() method with String and Object in Java

后端 未结 7 685
情话喂你
情话喂你 2021-02-02 03:11
Object o1 = new Object();
Object o2 = new Object();
//o1=o2;
System.out.println(o1.equals(o2));

It returns false. It can return true

7条回答
  •  情深已故
    2021-02-02 03:49

    The equals implemented in the Object class only compare references. Here is the source code:

    public boolean equals(Object obj) {
    return (this == obj);
    }
    

提交回复
热议问题