简介
对于 Data 注解基本理解而言就是生成 getter & setter 函数
但是经过探究
不单单有getter & setter 还有 toString方法 hashCode 方法 和 equals 方法。
原代码
import lombok.Data;
@Data
public class TestDTO {
private Integer age;
private String name;
}
编译后的代码
public class TestDTO {
private Integer age;
private String name;
public TestDTO() {
}
public Integer getAge() {
return this.age;
}
public String getName() {
return this.name;
}
public void setAge(final Integer age) {
this.age = age;
}
public void setName(final String name) {
this.name = name;
}
public boolean equals(final Object o) {
if (o == this) {
return true;
} else if (!(o instanceof TestDTO)) {
return false;
} else {
TestDTO other = (TestDTO)o;
if (!other.canEqual(this)) {
return false;
} else {
Object this$age = this.getAge();
Object other$age = other.getAge();
if (this$age == null) {
if (other$age != null) {
return false;
}
} else if (!this$age.equals(other$age)) {
return false;
}
Object this$name = this.getName();
Object other$name = other.getName();
if (this$name == null) {
if (other$name != null) {
return false;
}
} else if (!this$name.equals(other$name)) {
return false;
}
return true;
}
}
}
protected boolean canEqual(final Object other) {
return other instanceof TestDTO;
}
public int hashCode() {
int PRIME = true;
int result = 1;
Object $age = this.getAge();
int result = result * 59 + ($age == null ? 43 : $age.hashCode());
Object $name = this.getName();
result = result * 59 + ($name == null ? 43 : $name.hashCode());
return result;
}
public String toString() {
return "TestDTO(age=" + this.getAge() + ", name=" + this.getName() + ")";
}
}
标签:return,name,age,Object,other,注解,Data,public
From: https://www.cnblogs.com/eat-too-much/p/16586735.html