eclipse lombok 标红_eclipse集成lombok注解不起作用

本文介绍了如何在Eclipse中安装Lombok,包括下载、安装步骤,并详细描述了解决注解不起作用的问题。在安装过程中,发现eclipse.ini文件未正确配置,通过检查并添加缺失的配置项,成功解决了Lombok注解不生效的错误。
摘要由CSDN通过智能技术生成

安装步骤:

步骤一:lombok的下载地址为:https://projectlombok.org/download,jar包很小。这里也把依赖写出来:

org.projectlombok

lombok

1.18.2

provided

步骤二:双击jar包,jar包内的安装器会自动运行寻找eclipse

步骤三:选择需要安装的eclipse,然后点击安装(Install/Update),下一步会提示安装成功。

这就完成了安装,是不是很简单,我们看一下,安装过程具体操作了什么:

原来是做了两部分,第一,把jar包复制到了eclipse安装目录,第二在eclipse.ini文件中加入了一句话:-javaagent:D:\eclipse_4.4\eclipse\lombok.jar

接下来就是测试一下了,但是博主在这遇到了问题,耗费了一点时间来解决。

测试步骤:

重启eclipse,将jar包导入到工程,写测试类,在这遇到了错误:

报错,这说明注解没起作用,这就纳闷了,我重新按步骤做了一遍,然后切换了lombok版本,这些方法都试了,结果还是不行,偶然注意到了下面这句:

对,就是安装成功的提示,后面标红的没问题,这是具体jar工作的的一环,但是前面标红这句,我看了一下eclipse.ini文件,还真没有,我抱着试试原则,结果就是这个原因,注解起作用了。

最后看一下源文件和编译后的文件。

Test.java:

packagetest;importlombok.Data;

@Datapublic classTest {privateString name;privateString age;public static voidmain(String[] args) {

Test se= newTest();

se.setName("zhangsan");

se.setAge("16");

System.out.println(se.getAge());

System.out.println(se.getName());

}

}

Test.class:

packagetest;public classTest {privateString name;privateString age;public static voidmain(String[] args) {

Test se= newTest();

se.setName("zhangsan");

se.setAge("16");

System.out.println(se.getAge());

System.out.println(se.getName());

}publicString getName() {return this.name;

}publicString getAge() {return this.age;

}public voidsetName(String name) {this.name =name;

}public voidsetAge(String age) {this.age =age;

}public booleanequals(Object o) {if (o == this) {return true;

}else if (!(o instanceofTest)) {return false;

}else{

Test other=(Test) o;if (!other.canEqual(this)) {return false;

}else{

Stringthis$name = this.getName();

String other$name=other.getName();if (this$name == null) {if (other$name != null) {return false;

}

}else if (!this$name.equals(other$name)) {return false;

}

Stringthis$age = this.getAge();

String other$age=other.getAge();if (this$age == null) {if (other$age != null) {return false;

}

}else if (!this$age.equals(other$age)) {return false;

}return true;

}

}

}protected booleancanEqual(Object other) {return other instanceofTest;

}public inthashCode() {boolean PRIME = true;byte result = 1;

String $name= this.getName();int result1 = result * 59 + ($name == null ? 43: $name.hashCode());

String $age= this.getAge();

result1= result1 * 59 + ($age == null ? 43: $age.hashCode());returnresult1;

}publicString toString() {return "Test(name=" + this.getName() + ", age=" + this.getAge() + ")";

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值