In this post under Lombok I will explain with example the purpose of “@Singular” annotation which is alwayse used with “@Builder” annotation. In previous post under lombok I have explained why we use “@Builder” annotation i.e., to implement builder pattern. So if have below pojo class with “@Builder” annotation at the class level Pojo class…… Continue reading Using @Singular with @Builder annotation example
Tag: Lombok
Using @Builder annotation example
In this post under Lombok, I will show with example how to use “@Builder” annotation to implement Builder Pattern in our application. For our example, we use the below Person pojo class. Person class package package26; public class Person { private String name; private String city; @Override public String toString() { StringBuilder stringBuilder = new…… Continue reading Using @Builder annotation example
@Cleanup calling custom method
In the previous post under Lombok, I explained with purpose of “@Cleanup” annotation. “@Cleanup” annotation applied to any field assumes it as a resource and closes it just before the program ends. By default it assumes that the annotated field or resource or the instance has a method named “close” and when the time comes…… Continue reading @Cleanup calling custom method
@Cleanup annotation example
In this post under Lombok, I will explain with example the purpose of “@Cleanup” annotation. In Java whenever we open a resource, we have to close it after we are done with the resource. Usually all resource will have “close” method. We call that “close” method to close the resource. To do this in Java,…… Continue reading @Cleanup annotation example
Using @Value example
In all my previous posts under Lombok, I used Pojo classes as an example. All these Pojo classes are mutable since they have setter and getter method. In this post, I will show with example how to create an immutable class. To create an immutable class, we annotate a Pojo class with “@Value” annotation and…… Continue reading Using @Value example
Using @Getter(lazy=true) example
In this post under Lombok, I will explain with example the purpose of “@Getter(lazy=true)” annotation. In many cases, the values of Pojo class instance variables are fixed. In some cases, these values have to be computed at runtime. We can add a getter method which when called first time, will compute the value once and…… Continue reading Using @Getter(lazy=true) example
Using @Data annotation example
In this post under Lombok, I will explain with example the purpose and how to use “@Data” annotation. In all my previous posts under Lombok,1) if I need to add getter, setter I would add “@Getter” and “@Setter” annotation2) if I need to add toString method, I would add “@ToString” annotation3) if I need to…… Continue reading Using @Data annotation example
Using @Log annotation example
In this post under Lombok, I will show with example what is the purpose of “@Log” annotation and how to use it. In our software development, logging data (whether it is just an info, error, etc) to log files is important. These log data help developers to figure out what is happening in the application,…… Continue reading Using @Log annotation example
Using @AllArgsConstructor annotation example
In this post under Lombok, I will explain the purpose of “@AllArgsConstructor” annotation and how to use it. This annotation when added at class level, automatically creates a constructor with all the fields present in the class. If a field is annotated with “@NonNull” annotation, the automatically generated constructor code will add a null check…… Continue reading Using @AllArgsConstructor annotation example
Using @RequiredArgsConstructor and @NonNull annotation example
In this post under Lombok, I will explain with example what is the purpose of “@RequiredArgsConstructor” annotation and how to use it with “@NonNull” annotation. This annotation is applied at the class level and when applied it generates constructor with a parameter for each required fields. Note: It will also add a parameter for non-initialized…… Continue reading Using @RequiredArgsConstructor and @NonNull annotation example