2018-11-01

Lombok @Builder example

The @Builder annotation produces complex builder APIs for your classes.

Java With Out Lombok


public class BuilderExample {
  private String name;
  private int age;
 
  BuilderExample(String name, int age) {
    this.name = name;
    this.age = age;
    this.occupations = occupations;
  }
  //setter and getter
}

With Lombok


import lombok.Builder;
import lombok.Singular;

@Builder
public class BuilderExample {
  private String name;
  private int age;
}

Lombok with java 8 example

BuilderExample.builder().name("Test").age(20).build();


No comments:

Post a Comment