I usually project development necessary framework
- The strongest network request Net on Android
- The strongest list on Android (including StateLayout) BRV
- Android’s strongest default page StateLayout
- JSON and long text log printing tool LogCat
- Supports asynchronous and global customization of the toast tool Tooltip
- Develop the debugging window tool DebugKit
- One line of code creates the transparent StatusBar StatusBar
Lombok Plugin
The framework generates some methods automatically (although they can be generated quickly using AndroidStudio), but the increased code volume affects readability.
I want my POJO to only have fields;
- Add the dependent
compile "Org. Projectlombok: lombok: 1.16.18."
annotationProcessor 'org. Projectlombok: lombok: 1.16.18'
Copy the code
Both plug-ins and dependencies need to be added to be valid
- Installing a plug-in
- Start the animation progress
File/DefaultSettings/ Compiler, Annotation Processors. Click enable Annotation Processing
Method of use
A constructor
- @NoArgsConstructor
- @RequiredArgsConstructor
- @AllArgsConstructor
No arguments structure
@NoArgsConstructor(access = AccessLevel.PUBLIC, force = true, staticName = "of")
public class User {
private String name;
private int age;
}
Copy the code
- Default permissions for constructors created by access
public
- Force Whether final fields are initialized by default
- StaticName Whether to generate static method creation instances (and private same-argument constructors)
Have the cords structure
The parameter constructor implemented by default only implements fields modified by final and @nonNULL
@allargsconstructor requires that all fields be used as constructor arguments, but not as @nonNULL or Final
@Getter/@Setter
@Getter
@Setter
public class User {
private String name;
private int age;
public User(String name, int age) {
this.age = age;
this.name = name; }}Copy the code
@ToString
Automatically generates the toString() method
@EqualsAndHashCode
Methods for automatically generating Eaquls and HashCode. Equivalent to IDE generated.
@Builder
User user1 = User.builder().name(Daniel Wu).age(22).build();
Copy the code
@Data
This annotation is equivalent to using the following annotations at the same time
- @see Getter
- @see Setter
- @see RequiredArgsConstructor
- @see ToString
- @see EqualsAndHashCode
- @see Value
@Value
The difference with @data is that all fields or methods that are not modified by @nonfinal annotations are given Final. And there’s no Setter method
And classes decorated with @Value are also decorated with Final and cannot be inherited.
@Cleanup
Objects marked by this annotation are automatically closed;
public void testCleanUp() {
try {
@Cleanup ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(new byte[] {'Y'.'e'.'s'}); System.out.println(baos.toString()); } catch (IOException e) { e.printStackTrace(); }}Copy the code
@NonNull
Variables marked by this annotation will automatically throw a null pointer exception. You need to catch the exception yourself, otherwise the program crashes.
val
A local variable without type. JavaScript like data types. Plug-ins infer data types from context;
@Synchronized
Methods or variables that are annotated automatically add synchronization locks
@Singular
Can only be used in conjunction with the @Builder annotation
@Singular("ba_mei") private List<String> girls; / / the use of the User. The builder (). Ba_mei ("New Gen Knot clothes").clearGirls();
Copy the code
@Accessors
@Data
@Accessors(chain = true, fluent = true, prefix = "n")
public class User {
private String nAme = "";
private Integer age;
@Singular("ba_mei")
private List<String> girls;
}
Copy the code
- Setter for chain Builder pattern
- Direct use of Fluent
The field name ()
The construction method of - Prefix is valid for hump naming, ignoring the prefix