Lombok (Java Library)
Original author(s) | Reinier Zwitserloot |
---|---|
Written in | Java |
Engine | |
Type | Java library |
License | MIT License |
Search Lombok (Java Library) on Amazon.
The Project Lombok (also known as Lombok) is a Java library and annotation processor for the Java platform. The library core features can be used by any Java application, but there are some requirements to make it work with Integrated development environments such IntelliJ IDEA or Eclipse IDE.
The main feature of Lombok is to automate the generation of Java Beans getters and setters by using annotations.
Basic usage[edit]
The basic annotations @Getter
and @Setter
will automatically generate accessors method for you at the compilation time, what means you can still using setAge()
and getAge()
without having these methods implicitly.
The following is a rudimentary example of a JavaBean using Lombok:
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
public class GetterSetterExample {
@Getter @Setter private int age = 10;
@Setter(AccessLevel.PROTECTED) private String name;
@Override
public String toString() {
return String.format("%s (age: %d)", name, age);
}
}
The following is a rudimentary example of a vanilla (not using Lombok) JavaBean:
public class GetterSetterExample {
private int age = 10;
private String name;
@Override
public String toString() {
return String.format("%s (age: %d)", name, age);
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
protected void setName(String name) {
this.name = name;
}
}
On the compilation step, Lombok will create these mutator methods for you and the generated bytecode will be practically identical.
References[edit]
- Project Lombok Official website. Project Lombok Official website.
- Lombok API Documentation. Lombok API Documentation.
- Project Lombok: Clean, Concise Java Code. Oracle Corporation blog article about Lombok Project by Josh Juneau.
- Project Lombok – Boilerplate Buster. Avenga blog article about Lombok Project.
- Introduction to Project Lombok. Baeldung blog article about Lombok Project.
- Reducing boilerplate code with Project Lombok. Objectcomputing blog article about Lombok Project.
- Advantages and disadvantages of using Project Lombok. Nullbeans blog article about Lombok Project.
- Open source projects using Lombok at GitHub. GitHub projects using Lombok.
- Wikipedia Composition over inheritance. Wikipedia Composition over inheritance Lombok mention. (8 March 2015).
- IntelliJ IDEA 2020.3 Lombok support announcement. IntelliJ IDEA 2020.3 Lombok plugin built-in by default announcement. (26 October 2020).
- Kotlin language official Lombok support announcement. Kotlin language official Lombok support announcement. (24 June 2021).
External links[edit]
This article "Lombok (Java Library)" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Lombok (Java Library). Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.