package com.example.demo.test;
public class Person {
private String userName;
private String age;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
package com.example.demo.test;
public class Test {
public static void main(String[] args) {
Person p1 = new Person();
Person p2 = new Person();
System.out.println(p1.equals(p2));
System.out.println(p1 == p2);
/*
* String类重写了Object类的equals()方法,比较是两个对象的实体内容"是否完全相同。
*/
String s1 = new String("AA");
String s2 = new String("AA");
System.out.println(s1.equals(s2));
System.out.println(s1 == s2);
}
}