Jack Thomson
Jack Thomson

Reputation: 193

lombok @Data and @Getter don't give getter function

I am using a simple code:

import lombok.Data;
import lombok.Getter;

@Data
public class MyClass {
    @Getter
    String id;

    public MyClass(String id) {
        this.id = id;
    }
}

but when I instantiate that class, I don't have the getId() method though I added getter and Data

Upvotes: 0

Views: 547

Answers (4)

dhanyn10
dhanyn10

Reputation: 982

For linux user(i have linux mint vanessa)

  • follow instuction here: https://www.baeldung.com/lombok-ide
    after you download the jar file, run the jar by this command(example im using version 1.18.24):

    java -jar lombok-1.18.24.jar
    

    by default, the program will search the eclipse installation automatically. But if the program failed, you can search the eclipse manually.

  • If you failed to search the eclipse manually, you can reinstall it from official installer here: https://www.eclipse.org/downloads/packages/installer, so you will need to download tar.gz file.

  • Extract and run the installer file, then you will able to manually set the eclipse installation location.

  • Next, follow again the instruction from baeldung site.

Upvotes: 0

Eshu
Eshu

Reputation: 519

I have also added lombok to my IDE. I used STS and to use lombok I have added lombok jar to my project then double clicked on the lombok jar which opened the configuration window there I have just provided my IDE path(from my local machine) to lombok and then just restarted the application and it worked.

You can try the same.

Upvotes: 0

baklarz2048
baklarz2048

Reputation: 10938

Code is ok. Problem is the IDE configuration.

idea:

  • enable annotation processing
  • install lombok plugin

https://www.baeldung.com/lombok-ide

Upvotes: 1

Mars Tian
Mars Tian

Reputation: 1

import lombok.Data;

@Data
class MyClass {
    private String id;
    MyClass(String id) {
        this.id = id;
    }
}

class InitialMyClass {
    String initialId() {
        String id = "123";
        MyClass myClass = new MyClass(id);
        return myClass.getId();
    }
}

It works

Upvotes: 0

Related Questions