public @Data class Person { ... }
As I know, when I mark a class with the @Data
annotation, Lombok will provide getters for all fields, setters for all non-final fields. I want to turn off getter and setter only for one instance non-final field, how can I reach that?
What did I expect? To find an annotation like
@Setter(provide=false)
@Getter(provide=false)
private Map<...> dialogs;
or
@Data(excludeFields={"dialogs"})
I googled a lot and looked for on the official site, but I've found nothing.
Your help will be appreciated. Thank you.
All generated getters and setters will be public. 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.
Thus: you avoid getters and setters by thinking in terms of behavior, not in terms of state. Getters/setters manipulate state, from the "outside" (by doing avail = purse.
From Lombok documentation: You can always manually disable getter/setter generation for any field by using the special AccessLevel. NONE access level. This lets you override the behaviour of a @Getter, @Setter or @Data annotation on a class.
You can use @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
on the field as described on the website.
Disclosure: I am a Lombok developer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With