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
On
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.
Xin@XArgsConstructoris just a placeholder forNo,RequiredorAll.The real annotations are
@NoArgsConstructor,@RequiredArgsConstructorand@AllArgsConstructor. Pick one of these (I'd go for@AllArgsConstructorby default), and it'll work.