Using @Data annotation in Project Lombok

You are tired of declaring the Getter, Setter, toString(), equals() and hashCode() method for each class that we want to use these methods. Using @Data annotation in Project Lombok can help us avoid this problem.

Let’s create a Maven project for example:

Using @Data annotation in Project Lombok

With Project Lombok dependency as below:

Remember that, in order for the IDE can understand the code, we need to install Project Lombok plugin into our IDE. See construction for IntelliJ IDEA at here.

Now, for example, I have a Student class with some information like firstName, middleName, lastName and country. Without using Project Lombok library, I must declare Student bean as below:

With Project Lombok, we can remove all of these methods here. Just with @Data annotation in Project Lombok.

Very simple and clean.

If you check the Student.class file in /target/classes/com/huongdanjava/lombok, you will see the content as below:

Add Comment