Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Lombok "@Getter" is not applicable to field

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.

like image 845
Metamist Avatar asked Feb 15 '16 12:02

Metamist


People also ask

How do I exclude a field in Lombok getter?

To override the access level, annotate the field or class with an explicit @Setter and/or @Getter annotation. You can also use this annotation (by combining it with AccessLevel. NONE) to suppress generating a getter and/or setter altogether. Show activity on this post.

What is @getter and @setter in spring boot?

Getters and Setters play an important role in retrieving and updating the value of a variable outside the encapsulating class. A setter updates the value of a variable, while a getter reads the value of a variable.

How do you bypass Lombok getter?

To override the access level, annotate the field or class with an explicit @Setter or @Getter annotation.


1 Answers

Use

import lombok.Getter;

instead of:

import jdk.nashorn.internal.objects.annotations.Getter;
like image 167
Liviu Stirb Avatar answered Sep 25 '22 21:09

Liviu Stirb