Eclipse中Lombok的安装和注解说明
Posted gdjlc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Eclipse中Lombok的安装和注解说明相关的知识,希望对你有一定的参考价值。
Lombok 可用来帮助开发人员消除 Java 的重复代码,尤其是对于简单的 Java 对象(POJO),比如说getter/setter/toString等方法的编写。它通过注解实现这一目的。
官网:https://projectlombok.org
一、Eclipse中Lombok的安装
1、官网下载jar包当前版本是1.18.4,下载下来是一个lombok.jar
2、将lombok.jar移到eclipse的安装目录,即eclipse.in的同级目录
3、在eclipse.in文件最后加入下面两行
-Xbootclasspath/a:lombok.jar
-javaagent:lombok.jar
备注:
如果使用Lombok程序报错,可以点击eclipse菜单的Project选项的clean,清理一下即可。
二、Lombok注解说明
注解详见官网https://projectlombok.org/features/all
val
Finally! Hassle-free final local variables.
var
Mutably! Hassle-free local variables.
@NonNull
or: How I learned to stop worrying and love the NullPointerException.
@Cleanup
Automatic resource management: Call your close()
methods safely with no hassle.
@Getter/@Setter
Never write public int getFoo() {return foo;}
again.
@ToString
No need to start a debugger to see your fields: Just let lombok generate a toString
for you!
@EqualsAndHashCode
Equality made easy: Generates hashCode
and equals
implementations from the fields of your object..
@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor
Constructors made to order: Generates constructors that take no arguments, one argument per final / non-nullfield, or one argument for every field.
@Data
All together now: A shortcut for @ToString
, @EqualsAndHashCode
, @Getter
on all fields, and @Setter
on all non-final fields, and @RequiredArgsConstructor
!
@Value
Immutable classes made very easy.
@Builder
... and Bob‘s your uncle: No-hassle fancy-pants APIs for object creation!
@SneakyThrows
To boldly throw checked exceptions where no one has thrown them before!
@Synchronized
synchronized
done right: Don‘t expose your locks.
@Getter(lazy=true)
Laziness is a virtue!
@Log
Captain‘s Log, stardate 24435.7: "What was that line again?"
experimental
Head to the lab: The new stuff we‘re working on.
以上是关于Eclipse中Lombok的安装和注解说明的主要内容,如果未能解决你的问题,请参考以下文章