龙目岛:RequiredArgsConstructor无法正常工作 [英] Lombok: RequiredArgsConstructor not working

查看:1411
本文介绍了龙目岛:RequiredArgsConstructor无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎@RequiredArgsConstructor在下面的代码中不起作用.为什么呢?

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;
}

我得到了错误:

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

出于某种原因,它似乎可用于其他未定义构造函数而使用@RequiredArgsConstructor批注的领域类.

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

推荐答案

根据文档, 必需的参数是最终字段和具有约束的字段,例如@NonNull.

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

您需要将用户名设置为@NonNull

You need to make username as @NonNull

@NonNull private String username;

您也需要将它们定型.

And you need to make them final too.

这篇关于龙目岛:RequiredArgsConstructor无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆