Lombok: RequiredArgsConstructor not working

我是研究僧i 提交于 2020-04-09 03:47:30

问题


It seems that @RequiredArgsConstructor not working in the code below. Why is it?

import java.io.Serializable;

import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@RequiredArgsConstructor
public class User implements Serializable {

    private String username;

    /*public User(String username) {
        this.username = username;
    }*/

    private static final long serialVersionUID = 8043545738660721361L;
}

I get the error:

javax.faces.el.EvaluationException: java.lang.Error: Unresolved compilation problem: 
    The constructor User(String) is undefined

For some reason seems it does work for other domain class in which no constructor defined but instead used the @RequiredArgsConstructor annotation.


回答1:


According to Documentation, Required arguments are final fields and fields with constraints such as @NonNull.

You need to make username as @NonNull

@NonNull private String username;

And you need to make them final too.




回答2:


It's also worth noting for future readers that @Data also provides @RequiredArgsConstructor, so using both annotations isn't necessary :)




回答3:


Did you installed Lombok plugin in intellij ?

If not then

File -> Settings -> Plusings: Search for Lombok (CodeStream) version.

Restart the IDE and it should be fixed.

Double Check:

  • You have Lombok library installed using Maven or Gradle.
  • Enabled Annotation Processors from intellij IDE from File -> Settings: Search for Annotation Processors



回答4:


Try changing project/module JDK to 1.8.

Project Structure -> Project Settings->Project SDK and Project Language Level



来源:https://stackoverflow.com/questions/37671467/lombok-requiredargsconstructor-not-working

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