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
Category: Lombok
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
Using @EqualsAndHashCode cacheStrategy example
In this post under Lombok, I will explain with example the purpose of “cacheStrategy” attribute of “@EqualsAndHashCode” annotation. Just for recap, the annotation “@EqualsAndHashCode” when annotated to a POJO class, it generates “equals” and “hashCode” methods. Whenever the “hashCode” method of a POJO class is called, the hash is computed. To avoid computing of hashCode…… Continue reading Using @EqualsAndHashCode cacheStrategy example
Using @EqualsAndHashCode doNotUseGetters attribute example
In this post under Lombok, I will explain with example the purpose of “doNotUseGetters” attribute of “@EqualsAndHashCode” annotation. In a POJO class, we usually have getter method to return a formatted value of the actual value. For example, if we have a requirement where a employee has salary information stored as decimal but if he…… Continue reading Using @EqualsAndHashCode doNotUseGetters attribute example
Using @NoArgsConstructor annotation
In this post under Lombok, I will show with example the purpose of “@NoArgsConstructor” annotation. This annotation should be applied at the class level. When applied it generates a no argument constructor. Below is an example of how to use it Person class package package15; import lombok.NoArgsConstructor; @NoArgsConstructor public class Person { private String firstName;…… Continue reading Using @NoArgsConstructor annotation
Using @EqualsAndHashCode callSuper attribute
In this post under Lombok I will explain the purpose and how to use the “@EqualsAndHashCode” annotation’s “callSuper” attribute. In my previous post under “Using @EqualsAndHashCode annotation”, I explained with example the purpose of that annotation. Just for recap when this annotation is applied at class level it will automatically generates “equals” and “hashCode” methods…… Continue reading Using @EqualsAndHashCode callSuper attribute
Using @EqualsAndHashCode.Include annotation
In this post under lombok. I will explain the purpose and how to use “@EqualsAndHashCode.Include” annotation. In previous post “Using @EqualsAndHashCode.Exclude” I introduced you to “@EqualsAndHashCode.Exclude” annotation. Using “@EqualsAndHashCode.Exclude” annotation we are telling Lombok which fields should not be considered when generating “equals” and “hashCode” method of a POJO class. Now “@EqualsAndHashCode.Include” is reverse of…… Continue reading Using @EqualsAndHashCode.Include annotation
Using @EqualsAndHashCode.Exclude annotation
In this post under lombok, I will show with example the purpose of @EqualsAndHashCode.Exclude annotation. In the previous post, I explained with example the purpose of “@EqualsAndHashCode” annotation. It generates “equals” and “hashCode” method for the “@EqualsAndHashCode” annotated class. When generating “equals” and “hashCode” method it takes into consideration all the fields of the class.…… Continue reading Using @EqualsAndHashCode.Exclude annotation