...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@ToString
@NoArgsConstructor
@EqualsAndHashCode
public class Book {
private int id;
private String name;
private String author;
} |
Other useful Annotations:
@ToString
@Builder@NoArgsConstructor
@RequiredArgsConstructor
@EqualsAndHashCode @AllArgsConstructor and lot more ..
IDE's like Eclipse & IntelliJ does not detect the lombok annotations by default.
...
Go to File → Settings → Plugins → Browse Repositories. Search for lombok.
Lombok in Eclipse:
Download Lombok and run the Jar. Specify the eclipse location and click Install.
...
Check the eclipse installation of lombok in About eclipse.
Sample Generated class file:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public class Book
{
private int id;
private String name;
private String author;
public void setId(int id)
{
this.id = id;
}
public void setName(String name)
{
this.name = name;
}
public void setAuthor(String author)
{
this.author = author;
}
public String toString()
{
return "Book(id=" + getId() + ", name=" + getName() + ", author=" + getAuthor() + ")";
}
public boolean equals(Object o)
{
if (o == this) {
return true;
}
if (!(o instanceof Book)) {
return false;
}
Book other = (Book)o;
if (!other.canEqual(this)) {
return false;
}
if (getId() != other.getId()) {
return false;
}
Object this$name = getName();Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) {
return false;
}
Object this$author = getAuthor();Object other$author = other.getAuthor();return this$author == null ? other$author == null : this$author.equals(other$author);
}
protected boolean canEqual(Object other)
{
return other instanceof Book;
}
public int hashCode()
{
int PRIME = 59;int result = 1;result = result * 59 + getId();Object $name = getName();result = result * 59 + ($name == null ? 43 : $name.hashCode());Object $author = getAuthor();result = result * 59 + ($author == null ? 43 : $author.hashCode());return result;
}
public int getId()
{
return this.id;
}
public String getName()
{
return this.name;
}
public String getAuthor()
{
return this.author;
}
} |
Other useful Reference:
...