Reduce boilerplate getters/setters in java

  1. Getters and Setters
  2. Default ,No argument or All argument constructors
  3. toString() method
  4. equals() and hashcode () method
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
/**
* User : Tanvir Ahmed
* Date: 9/15/2020.
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class Client {

private String name;

private String country;

private String initials;

private String prefix;

}
/**
* User : Tanvir Ahmed
* Date: 9/15/2020.
*/
public class Client {


private String name;

private String country;

private String initials;

private String prefix;

public Client(String name, String country) {
this.name = name;
this.country = country;
}

public String getName() {
return name;
}

public String getCountry() {
return country;
}

public String getInitials() {
return initials;
}

public String getPrefix() {
return prefix;
}

public void setName(String name) {
this.name = name;
}

public void setCountry(String country) {
this.country = country;
}

public void setInitials(String initials) {
this.initials = initials;
}

public void setPrefix(String prefix) {
this.prefix = prefix;
}

}
@NoArgsConstructor -Implement a public constructor with no argument.@AllArgsConstructor -implement a public constructor with all the properties of the class as argument@RequiredArgsConstructor- Implement a public constructor with all final properties and those marked with @Nonnull annotation only
@AllArgsConstructor(access =AccessLevel.PROTECTED)
@EqualsAndHashCode
public class Client extends Person {
}
/**
* User : Tanvir Ahmed
* Date: 9/15/2020.
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder(builderClassName = "Builder", toBuilder = true)
public class Client {

private String name;

private String country;

private String initials;

private String prefix;


}

Client newClient= Client
.builder()
.name("Tanvir")
.build();
//@AllArgsConstructor
//@NoArgsConstructor
//@Getter
//@Setter
//@Builder(builderClassName = "Builder", toBuilder = true)
@Data
public class Client {

private String name;

private String country;

private String initials;

private String prefix;


}

--

--

--

Full stack software Developer.Major in Java And Android.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Struct Vs Proto Vs Class in Swift

Combining Data Sources: Transforming data for Performance & Clarity

Streamlining Themelio consensus with Streamlet

Operating Systems 101: Persistence — FSCK and Journaling(v)

Retrospectives: In Your Own Sweet Way

CSS Padding a Magic Wand

How smart should be your smartphone?

April 2021 Recap

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TanvirChowdhury

TanvirChowdhury

Full stack software Developer.Major in Java And Android.

More from Medium

Why Spring Boot is called opinionated?

Spring AOP — Using Java annotation as pointcut expressions

Collection Framework in Java

Chapter 02 — Classes and Objects