当前位置:网站首页>Farewell to Lombok in 996
Farewell to Lombok in 996
2022-06-25 05:37:00 【Which floor do you rate moto】
Realization principle
Examples of common annotations
rely on
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
// Express jar Packages run at compile time
<scope>provided</scope>
</dependency>
Explanation of notes
- @Getter: Generated field get Method
- @Getter(lazy = true) : Lazy loading , Must use final Decorate the field value
- @Getter(value = AccessLevel.PRIVATE,onmethod _={@Notnull})
- value = AccessLevel.PRIVATE: Set the generated get Method's access level
- onmethod _={@Notnull}: For the generated get Method to add additional annotations
- @Setter annotation : Generate set Method
- @Setter(value = AccessLevel.PRIVATE,onparam _={@Notnull})
- onparam _={@Notnull}: Add additional annotations to the parameters
- @Setter(value = AccessLevel.PRIVATE,onparam _={@Notnull})
- @ToString annotation
- @ToString(exclude = {“ Property value ”}) : The attribute value does not generate tostring Method
- @EqualsAndHashCode annotation : Generate for this class equals Methods and hashcode Method
- The annotation also has some parameters that can be set : For example, exclude some fields
- @Data annotation : Large and comprehensive notes
- contain :@Getter,@Setter,@ToString,@EqualsAndHashCode
- @NonNull annotation
Generated after adding annotations .class file
- @AllArgsConstructor,@NoArgsConstructor,@RequiredArgsConstructor
- @AllArgsConstructor: Generate a parametric construct
- @NoArgsConstructor: Generate a nonparametric construct
- @RequiredArgsConstructor
- @Cleanup annotation : Marking on the flow to be closed will automatically close the flow , The effect is equivalent to try-with-source
Lombok Advantages and disadvantages
- advantage
- Automatically generate template code through annotations , Improve development efficiency
- The code is concise , Focus only on related attributes
- After adding a new attribute , There is no need to modify the relevant methods
- shortcoming
- Reduces the readability and integrity of the source code
- Make troubleshooting more difficult
- need IDE Support for related plug-ins
- @slf4j annotation ,@Builder annotation ,@singular annotation
@Slf4j annotation : Simplify the log import method to work on classes
@Builder annotation : Simplify the process of creating objects
@singular annotation : coordination @Builder annotation , Simplify set type operations
Log system
- @slf4j annotation
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
// Bridge package
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
- @Builder Notes and @singular annotation
@Builder Completely separate the creation of objects from the use of objects
@Builder Add to class : Static attributes cannot be assigned , Initialized final Field cannot be assigned
The initialized values of common attribute fields cannot be brought in this way
@Builder
public class BuilderTest{
// Static attribute
private static Stirng staticField;
//final attribute
private final Stirng finalField;
//final attribute
private final Stirng finalField = " Already initialized final attribute ";
// General attribute
private Stirng staticField;
// Collection class properties
@Singular
private List<String> listFields;
}
// Already initialized final Field cannot be assigned , Static fields cannot be assigned
// The initialized values of common attribute fields cannot be brought in this way
// add @Singular after :builder Object time , You can add a field string , You can also add a collection
边栏推荐
- Use js to simply implement the apply, call and bind methods
- JSON Library Tutorial from scratch (I): starting to learn and organize notes
- CTFHub-rce
- ERDAS 9.2 installation tutorial
- What happens when you use "-fno exceptions", "new T"- With “-fno-exceptions”, what happens with “new T”?
- Word of the Day
- Using JS to realize the sidebar of life information network
- cuda编译报错
- Personalized Federated Learning with Moreau Envelopes
- Semantic segmentation cvpr2019-advance: advantageous enterprise minimization for domain adaptation in semantic segmentation
猜你喜欢
Deep analysis of recursion in quick sorting
Everything is an object
Deep analysis of epoll reactor code
Dynamic programming example 2 leetcode62 unique paths
Double recursion in deep analysis merge sort
A review of small sample learning
Excel splits a worksheet into multiple worksheets according to conditions, and how to split multiple worksheets into independent tables
C language - minesweeping
JSON Library Tutorial from scratch (I): starting to learn and organize notes
2.20 learning content
随机推荐
JMeter stress testing and agent recording
Deep analysis of recursion in quick sorting
Array: force deduction dichotomy
MySQL -- optimize query statements and use not in with cases
Deeply understand the characteristics of standard flow and off standard elements
By inserting a section break, the word header, footer, and page number can start from any page
Pointer array function combination in C language
Understand JS high-order function and write a high-order function
Five simple data types of JS
Mobile number regular expression input box loses focus verification
Detailed summary of float
2021-03-23
Charles and iPhone capture
Word of the Day
DOM document object model (I)
Even if you are not good at anything, you are growing a little bit [to your 2021 summary]
Analysis of IM project framework
Essais de pénétration - sujets d'autorisation
First blog
2.20 learning content