@NonNull 注解无法编译

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

@NonNull lombok failed to compile

问题

以下是翻译好的部分:

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

  1. @Getter
  2. @Setter
  3. public class Test {
  4. private Integer id;
  5. private String name;
  6. }

这里是一个简单的方法:

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

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

  1. 16:25:46 [ERROR] /var/jenkins_home/TestMapper.java:[59,93] 找不到符号
  2. 16:25:46 [ERROR] 符号: 方法 getName()
  3. 16:25:46 [ERROR] 位置: 类型为 @lombok.NonNull Test 的变量 test
  4. var test = new Test();
  5. 我将收到相同的错误

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

英文:

Here is simple dto

  1. @Getter
  2. @Setter
  3. public class Test{
  4. private Integer id;
  5. private String name;
  6. }

here is simple method

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

when i tried to build project i got an error

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

i will get same Error

答案1

得分: 1

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

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

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

英文:

You should update your method to this

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

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:

确定