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();


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation