Thursday, February 16, 2023

Lombok Sample @Data along with Generated Code

 @Data, on the other hand, generates boilerplate code for a class that includes fields, getters, setters, equals, hashCode, and toString methods.

Original: 

 import lombok.Data;


@Data
public class Person1 {
String name;
int age;
}


Generated :


//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
public class Person1 {
String name;
int age;

public Person1() {
}

public String getName() {
return this.name;
}

public int getAge() {
return this.age;
}

public void setName(final String name) {
this.name = name;
}

public void setAge(final int age) {
this.age = age;
}

public boolean equals(final Object o) {
if (o == this) {
return true;
} else if (!(o instanceof Person1)) {
return false;
} else {
Person1 other = (Person1)o;
if (!other.canEqual(this)) {
return false;
} else if (this.getAge() != other.getAge()) {
return false;
} else {
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 Person1;
}

public int hashCode() {
int PRIME = true;
int result = 1;
int result = result * 59 + this.getAge();
Object $name = this.getName();
result = result * 59 + ($name == null ? 43 : $name.hashCode());
return result;
}

public String toString() {
return "Person1(name=" + this.getName() + ", age=" + this.getAge() + ")";
}

} 

No comments:

Post a Comment