@NonNull 注解无法编译

huangapple go评论54阅读模式
英文:

@NonNull lombok failed to compile

问题

以下是翻译好的部分:

这里是一个简单的DTO(数据传输对象):

@Getter
@Setter
public class Test {
    private Integer id;
    private String name;
}

这里是一个简单的方法:

public String testName(@NonNull Test test) {
    return test.getName();
}

当我尝试构建项目时,我收到了一个错误消息:

16:25:46 [ERROR] /var/jenkins_home/TestMapper.java:[59,93] 找不到符号
16:25:46 [ERROR]   符号:   方法 getName()
16:25:46 [ERROR]   位置: 类型为 @lombok.NonNull Test 的变量 test

var test = new Test();

我将收到相同的错误

请注意,变量名 test 需要具备 getName() 方法,但错误信息中提到找不到该方法。

英文:

Here is simple dto

@Getter
@Setter
public class Test{
private Integer id;
private String name;
}

here is simple method

public String testName(@NonNull Test test){
return test.getName();
}

when i tried to build project i got an error

16:25:46 [ERROR] /var/jenkins_home/TestMapper.java:[59,93] cannot find symbol
16:25:46 [ERROR]   symbol:   method getName()
16:25:46 [ERROR]   location: variable test of type @lombok.NonNull Test

var test = new Test();

i will get same Error

答案1

得分: 1

你应该将你的方法更新为这样:

public String testName(@NonNull Test test){
return test.getName();
}

你应该为方法调用添加 '()'。

英文:

You should update your method to this

public String testName(@NonNull Test test){
return test.getName();
}

You should add '()' for method call.

huangapple
  • 本文由 发表于 2023年7月20日 22:17:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730822.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定