15

I am trying to use lombok getters and setters annotations. As far as I know the annotated code is generated at runtime and not compile time so how can take the help of autogenerated getters and setters for writing 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 such annotations if these are not generated while 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 these since there are no setters and getters generated for me in eclipse while writing code..

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

Stephan
  • 41,764
  • 65
  • 238
  • 329
Scorpion
  • 633
  • 3
  • 11
  • 24
  • 2
    Have you tried the Eclipse plugin? Also, you misspelled Lombok everywhere. – Antimony Jun 15 '13 at 03:23
  • It is used for accessing properties using Interospection, for example what is done with most MVC frameworks in binding request parameters to properties, or what is done with Hibernate and .... – Amir Pashazadeh Jun 15 '13 at 03:32
  • 3
    @user well you'll have to tell us what "lambok" is then because nothing turns up on Google. Despite your denials the prior is strongly in favor of you using the misspelled Lombok library. – Antimony Jun 15 '13 at 03:34

3 Answers3

12

First of all, Lombok does run compile time to change the generated class file on the fly.

Possibly, lombok is not correctly installed in your Eclipse. See this answer on lombok installation problems in Eclipse.

Furthermore, the runtime processing of annotations is not the only use for them. Java 5 already shipped with apt, the Annotation Processing Tool and since java 6 annotations can be processed by the standard compiler (javac). Annotations can generate class files, source files or other resource files.

Disclosure: I am one of the Project Lombok developers

Community
  • 1
  • 1
Roel Spilker
  • 32,258
  • 10
  • 68
  • 58
  • @Roel_Spilker Is there a way to configure Lombok to put Hibernate annotations on Getters instead of properties? – Paulo Pedroso Jul 02 '16 at 14:34
  • Why Setter and Getter is having meta-annotation `@Target({ElementType.FIELD, ElementType.TYPE})` but cannot be applied on annotations? – Tiina Jan 24 '18 at 03:31
3

Make sure you Restart Eclipse/Intellij or Any IDE that you are working in after adding Lombok jars and plugins.

Anupam Haldkar
  • 985
  • 13
  • 15
Aditi Pal
  • 31
  • 1
1

I use Eclipse IDE. I have to install lombok in my computer before adding lombok library in pom.xml

Step 1: - Download lombok at https://projectlombok.org/download - Run command java -jar enter image description here - Restart your IDE - Finish

Step 2: - Add lombok to pom.xml file

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.8</version>
    <scope>provided</scope>
</dependency>
  • call getter / setter in your code enter image description here
Gim
  • 79
  • 1
  • 4