public class Person {
private String name;
private int age;
?
public Person() {
}
?
public Person(String name, int age) {
this.name = name;
this.age = age;
}
?
public String getName() {
return name;
}
?
public void setName(String name) {
this.name = name;
}
?
public int getAge() {
return age;
}
?
public void setAge(int age) {
this.age = age;
}
?
/*@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
?
Person person = (Person) o;
?
if (age != person.age) {
return false;
}
return name != null ? name.equals(person.name) : person.name == null;
}*/
?
public class Demo01Main {
public static void main(String[] args) {
String a = "haha";
String b = null;
boolean equals = Objects.equals(a, b);
System.out.println(equals);
}
}
原文:https://www.cnblogs.com/lxy522/p/12811799.html