Java Lombok "@Getter" is not applicable to field
Asked Answered
T

2

11

I've been trying to get Lombok working in IntelliJ IDEA but whenever I try to use any of its annotations, I get an error message that goes like this:

Error:(5, 5) java: annotation type not applicable to this kind of declaration

My code looks like this, using their example on their homepage.

import jdk.nashorn.internal.objects.annotations.Getter;

public class GetterSetterExample {
    @Getter
    private int age = 10;
}

I have installed the lombok plugin, and enabled the annotation processor in settings. I'm using IntelliJ 15 with java 1.8.0_40.

I can't find anyone with the same problem as me which is why I am asking here if anyone knows what's going on.

Thai answered 15/2, 2016 at 12:44 Comment(0)
I
32

Use

import lombok.Getter;

instead of:

import jdk.nashorn.internal.objects.annotations.Getter;
Increscent answered 15/2, 2016 at 12:48 Comment(0)
P
2

For Lombok to work properly, you have to install two things:

  1. lombok dependency (or single *.jar file for hardcod)
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.10</version>
      <scope>provided</scope>
    </dependency>
    
  2. plugin to your IDE so that it can see those implicit getters/setters.
Pennsylvania answered 16/9, 2019 at 22:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.