Creating enums with lombok

丶灬走出姿态 提交于 2019-12-22 05:15:55

问题


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


回答1:


You also have to have enabled "Enable annotation processing" in Settings -> Build -> Compiler -> Annotation Processor




回答2:


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.



来源:https://stackoverflow.com/questions/49837774/creating-enums-with-lombok

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!