EN
Lombok - what is the best way to omit one filed Setter/Getter in Lombok?
1 answers
8 points
I am looking for the best way to omit one field setter/getter in Lombok.
In my case all getters are defined on the entire class level. I am looking for annotation that is able to disable automatic generating getter and setter only for specific field.
Is it possible?
My source code:
xxxxxxxxxx
1
package com.gallery.requests;
2
3
import lombok.Getter;
4
import lombok.Setter;
5
import lombok.NoArgsConstructor;
6
import lombok.AllArgsConstructor;
7
8
9
10
11
12
public class ItemRequest
13
{
14
private String name;
15
private String description;
16
private Long owner; // <---------------------- I don't want to have generated getters and setters for this field.
17
18
// ...
19
}
1 answer
3 points
You should add to single field the following annotations:
xxxxxxxxxx
1
// import lombok.AccessLevel;
2
3
AccessLevel.NONE) // <--------------- the solution (
4
AccessLevel.NONE) // <--------------- the solution (
5
private Long owner;
Practical example:
xxxxxxxxxx
1
package com.gallery.requests;
2
3
import lombok.AccessLevel;
4
import lombok.Getter;
5
import lombok.Setter;
6
import lombok.NoArgsConstructor;
7
import lombok.AllArgsConstructor;
8
9
10
11
12
13
public class ItemRequest
14
{
15
private String name;
16
private String description;
17
18
AccessLevel.NONE) // <--------------- the solution (
19
AccessLevel.NONE) // <--------------- the solution (
20
private Long owner;
21
22
// ...
23
}
See also
0 commentsShow commentsAdd comment