How to actually make lombok annotations for getters and setters

I am trying to use lombok getters and seters annotations. As far as I know, annotated code is generated at runtime, not compilation time, and how can I use auto-generated getters and setters to write code?

for example i have a class like this

@lombok.Getters @lombok.Setters public class MyLombokTesting { private String userName; } 

but what is the use of annotations if they are not generated when writing code ...

Now i want to do something like this

 MyLombokTesting myLombokTesting = new MyLombokTesting(); String username = myLombokTesting.getUserName(); or myLombokTesting.setUserName("some username"); 

but I can’t do any of them, because during the eclipse during writing the code, setters and getters were not created for me.

Obviously, I can have one argument constructor to set the username, but what about getter?

+4
source share
2 answers

First of all, Lombok starts compilation time to change the created class file on the fly.

It may be that the clacker is not installed correctly in your Eclipse. See this answer for problems installing lombok in Eclipse.

In addition, processing annotations at runtime is not unique to them. Java 5 already comes with apt , Annotation Processing Tool, and since java 6 annotations can be handled by the standard compiler (javac). Annotations can generate class files, source files, or other resource files.

Disclosure: I am one of the developers of Project Lombok

+7
source

Restart Eclipse after adding Lombok banners.

+1
source

Source: https://habr.com/ru/post/1486344/


All Articles