I am using project lombok with my application. I was creating an enum. If I use
@AllArgsConstructor
annotation with my enum, it doesn't recognise the constructor, enum throws and error that it cannot take string argument.
How to resolve this?
import lombok.Getter; import lombok.AllArgsConstructor @AllArgsConstructor public enum Direction { NORTH("NORTH"), // all these enums give error, for no constructor SOUTH("SOUTH"), EAST("EAST"), WEST("WEST"); @Getter private String value; }
P.S.: I am using intellij-idea, which has lombok plugin install. My lombok dependency version is: 1.16.20
You can define the inner Fields enum/class yourself, in which case lombok will add all the enum constants / public static final fields you haven't written yourself.
Because there is only one instance of each enum constant, it is permissible to use the == operator in place of the equals method when comparing two object references if it is known that at least one of them refers to an enum constant.
Update: It's possible to have setters in enum types.
You can assign different values to enum member. A change in the default value of an enum member will automatically assign incremental values to the other members sequentially.
You also have to have enabled "Enable annotation processing" in Settings -> Build -> Compiler -> Annotation Processor
That’s usually an issue with your IDE, and strangely, it gets fixed after restarting the IDE. It’s when the plugin lombok is not in the effect yet.
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