I want to use lombok in a enum, but I can't find the annotation to generate the constructor. I checked the Lombok manual that it shows there should be a annotion named @XArgsConstructor,but I can't find it, any advice ? thanks.
how to generate constructor in a enum using Lombok
5.6k Views Asked by Japhy Fan At
2
There are 2 best solutions below
0

I know this is an old question but I'd want to add an example about how it should be done:
@AllArgsConstructor
public enum EnumExample {
CONSTANT("constant");
@Getter
private final String value;
}
Have in mind that the idea behind using enums is using objects rather than static constants. This will give benefits according how to manage the constant values.
X
in@XArgsConstructor
is just a placeholder forNo
,Required
orAll
.The real annotations are
@NoArgsConstructor
,@RequiredArgsConstructor
and@AllArgsConstructor
. Pick one of these (I'd go for@AllArgsConstructor
by default), and it'll work.