Lombok won't generate getter methods for variables when annotation is in class level

Viewed 1059

I'm quite confused as to why the annotation won't create getter methods for the variables if the annotation is at class level

@Getter
public class Config {

    private static final String TEST = "";
}

But creates the getters if annotation is at the variable level.


public class Config {
    @Getter
    private static final String TEST = "";
}

Thank you!

2 Answers

You can do this as the documentation says:

You can annotate a class with a @Getter or @Setter annotation. Doing so is equivalent to annotating all non-static fields in that class with that annotation. @Getter/@Setter annotations on fields take precedence over the ones on classes.

The problem you're seeing is because the field you're having problems with is static.

The problem is Class level Getter annotation doesn't work with Static fields. Check the Lombok documentation here. Please refer to the screenshot below --

enter image description here

Related