Home > Java > javaTutorial > body text

What is Lombok in Java? Use of Lombok

青灯夜游
Release: 2018-10-25 17:42:09
forward
4102 people have browsed it

The content of this article is to introduce what Lombok is? The use of Lombok. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Lombok is a Java utility that can be used to help developers eliminate Java verbosity, especially for simple Java objects (POJOs). It does this through annotations.

Take an example from lombok official website:

public class Users {
   private String name ;
   private String pass ;
   private Integer age ;
}
Copy after login

To use this object, you must also write some getter and setter methods, and you may also need to write a constructor, equals method, or hash method. These methods are verbose and non-technical; we call them boilerplate code.
The main function of lombok is to eliminate boilerplate code through some annotations, like this:

@Datapublic class Users{
    private String name;
    private String pass;
    private Integer age;
}
Copy after login

Then you can see that this class automatically generates these methods

What is Lombok in Java? Use of Lombok

If you think the @Data annotation is a bit simple and crude, Lombok provides some more sophisticated annotations, such as @Getter, @Setter, (these two are field annotations), @ToString, @AllArgsConstructor (these two are class annotations ).

These are probably the most common usages. For more detailed usage, see Lombok feature overview here.

------------------------------------The above are some functions of lombok-- --------------------------

lombok is both an IDE plug-in and a jar package that the project depends on

Download the lombok jar URL: https://atimo.oss-cn-beijing.aliyuncs.com/file/lombok .jar

The reason lombok relies on the jar package is because its annotations are used during compilation. It's because of the plug-in, which changes the bytecode generation by operating the AST (Abstract Syntax Tree) when the compiler compiles. In other words, it can change the Java syntax. It is not a runtime feature like spring's dependency injection or hibernate's ORM, but a compile-time feature.

The above is the detailed content of What is Lombok in Java? Use of Lombok. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!