当前位置:网站首页>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 
边栏推荐
- Array: force deduction dichotomy
- Two dimensional array and function call cases of C language
- JSON Library Tutorial from scratch (III): parsing strings, learning and sorting notes
- CTFHub-rce
- C style string
- Go Basics
- 2.20 learning content
- JMeter stress testing and agent recording
- Example of dynamic programming 3 leetcode 55
- JS verification code input number auto skip
猜你喜欢

Essais de pénétration - sujets d'autorisation

How to install the blue lake plug-in to support Photoshop CC 2017

Detailed summary of float

Personalized Federated Learning with Moreau Envelopes

ArcGIS Engine + Visual Studio installation tutorial

Various pits encountered in the configuration of yolov3 on win10

Notes on non replacement elements in the line (padding, margin, and border)

Semantic segmentation cvpr2019-advance: advantageous enterprise minimization for domain adaptation in semantic segmentation

Deep analysis of epoll reactor code

Jenkins installation and configuration
随机推荐
Handwritten promise all
Even if you are not good at anything, you are growing a little bit [to your 2021 summary]
Array and simple function encapsulation cases
ArcGIS Engine + Visual Studio installation tutorial
H5 native player [learn video]
滲透測試-提權專題
February 20ctf record
[Huawei machine test] hj16 shopping list
Classic usage of the sumproduct function
Matlab notes
Use js to simply implement the apply, call and bind methods
Dynamic programming example 1 leetcode 322 coin change
Semantic segmentation cvpr2019-advance: advantageous enterprise minimization for domain adaptation in semantic segmentation
[relax's law of life lying on the square] those poisonous chicken soup that seem to be too light and too heavy, but think carefully and fear
Read the general components of antd source code
Semantic segmentation fcns in the wild: pixel level adaptive and constraint based adaptation
Edge loss interpretation
Jason learning
Customize the console plot result style
Can bus extended frame