title: Lombok author: name: "Thomas Queste" url: "tomsquest.com" email: "[email protected]" twitter: "@ThomasQueste" output: index.html style: index.css controls: false
- Reduce boilerplate
- Reduce maintenance --
Given:
@Builder
public class Line {
private String adresseLigne1;
private String codePostal;
private String ville;
private CountryCode country;
}
Usage:
Line line = Line.builder()
.adresseLigne1("adresseLigne1")
.codePostal("codePostal")
.ville("ville")
.countryCode(CountryCode.DE)
.build();
--
Given:
@Value
public class Point {
private int x;
private int y;
}
Usage:
Point p = new Point(x,y);
p.getX()
p.getY()
p.toString()
new Point(1.2).equals( new Point(3,4) ) // + hashcode
--
Given:
@Data
public class Point {
private int x;
private int y;
}
Usage:
Point p = new Point();
p.setX(1)
p.setY(2)
p.toString()
new Point(1.2).equals( new Point(3,4) ) // + hashcode
--
Maven, Gradle, And, Kobalt...
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>
@Log
: declare a loggerval
: final local variable + type inferred@NonNull
: checks for nulls@Getter/@Setter
@ToString
@EqualsAndHashCode
@NoArgsConstructor
,@RequiredArgsConstructor
,@AllArgsConstructor
--
--
Fluent API for getters and setters, return this
instead of void
in setters
public Line country(CountryCode country) {
this.country = country;
return this;
}
line
.country(FR)
.name("FOO")
--
Immutable 'setters' - methods that create a clone but with one changed field
public Line withCountry(CountryCode country) {
return this.country == country ? this : new Line(idSocle, prenom, nom, country);
}
Line line2 = line1.withCountry(FR)
--
- IDE Plugin needed
- Source annotation enabled
- Java 9 unsupported as of 2017.10
- Many opened issues & PR