zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    WC2021 游记
    TC11054
    P5904
    CF741D
    CF1467 题解
    [CTSC2008]网络管理 [树剖+整体二分]
    [HNOI2015]接水果[整体二分]
    [SDOI2010]粟粟的书架 [主席树]
    整体二分的一些见解[整体二分学习笔记]
    P2710 数列[fhq treap]
  • 原文地址:https://www.cnblogs.com/gdjlc/p/10084014.html
Copyright © 2011-2022 走看看