Lombok @Getter and @Setter Annotations

You can annotate any field with @Getter and/or @Setter, to let lombok generate the default getter/setter automatically.
A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field’s type is boolean). A default setter is named setFoo if the field is called foo, returns void, and takes 1 parameter of the same type as the field. It simply sets the field to this value.

The generated getter/setter method will be public unless you explicitly specify an AccessLevel, as shown in the example below. Legal access levels are PUBLIC, PROTECTED, PACKAGE, and PRIVATE.

You can also put a @Getter and/or @Setter annotation on a class. In that case, it’s as if you annotate all the non-static fields in that class with the annotation.

import java.time.LocalDate;public class Person {String firstName; String lastName; LocalDate dateOfBirth;public String getFirstName() { return firstName; }public void setFirstName(String firstName) { this.firstName = firstName; }public String getLastName() { return lastName; }public void setLastName(String lastName) { this.lastName = lastName; }public LocalDate getDateOfBirth() { return dateOfBirth; }public void setDateOfBirth(LocalDate dateOfBirth) { this.dateOfBirth = dateOfBirth; }}

Using Lombok @Getter @Setter

@Getter @Setterpublic class PersonLombok { String firstName; String lastName; LocalDate dateOfBirth;}