在java bean定義的時(shí)候沼填,需要給每個(gè)字段提供set和get屬性。
lombok這個(gè)插件所做的事情就是在編譯期間替我們干了這件事岩饼。
下面提供兩個(gè)文件的比對:
原始文件:
@Data
@NoArgsConstructor
public class AdvertiserQueryVO {
private String advertiserName;
private String jdId;
private String status;
private String chargeType;
}
編譯后的class籍茧,反編譯出來的文件:
public class AdvertiserQueryVO {
private String advertiserName;
private String jdId;
private String status;
private String chargeType;
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof AdvertiserQueryVO)) return false;
AdvertiserQueryVO other = (AdvertiserQueryVO) o;
if (!other.canEqual(this)) return false;
Object this$advertiserName = getAdvertiserName();
Object other$advertiserName = other.getAdvertiserName();
if (this$advertiserName == null ? other$advertiserName != null : !this$advertiserName.equals(other$advertiserName))
return false;
Object this$jdId = getJdId();
Object other$jdId = other.getJdId();
if (this$jdId == null ? other$jdId != null : !this$jdId.equals(other$jdId)) return false;
Object this$status = getStatus();
Object other$status = other.getStatus();
if (this$status == null ? other$status != null : !this$status.equals(other$status)) return false;
Object this$chargeType = getChargeType();
Object other$chargeType = other.getChargeType();
return this$chargeType == null ? other$chargeType == null : this$chargeType.equals(other$chargeType);
}
public boolean canEqual(Object other) {
return other instanceof AdvertiserQueryVO;
}
public int hashCode() {
int PRIME = 59;
int result = 1;
Object $advertiserName = getAdvertiserName();
result = result * 59 + ($advertiserName == null ? 0 : $advertiserName.hashCode());
Object $jdId = getJdId();
result = result * 59 + ($jdId == null ? 0 : $jdId.hashCode());
Object $status = getStatus();
result = result * 59 + ($status == null ? 0 : $status.hashCode());
Object $chargeType = getChargeType();
result = result * 59 + ($chargeType == null ? 0 : $chargeType.hashCode());
return result;
}
public String toString() {
return "AdvertiserQueryVO(advertiserName=" + getAdvertiserName() + ", jdId=" + getJdId() + ", status=" + getStatus() + ", chargeType=" + getChargeType() + ")";
}
public String getAdvertiserName() {
return advertiserName;
}
public void setAdvertiserName(String advertiserName) {
this.advertiserName = advertiserName;
}
public String getJdId() {
return jdId;
}
public void setJdId(String jdId) {
this.jdId = jdId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getChargeType() {
return chargeType;
}
public void setChargeType(String chargeType) {
this.chargeType = chargeType;
}
public AdvertiserQueryVO() {
}
}
通過對兩個(gè)文件的比對硕糊,我們發(fā)現(xiàn)腊徙,加了@Data注解的類撬腾,編譯后會(huì)自動(dòng)給我們加上下列方法:
- 所有屬性的get和set方法
- toString 方法
- hashCode方法
- equals方法