An annotation processor which implements "Builder Pattern" for your java classes.
we annotated our class with @Builder
and initialize a constructor with all the fields.
@Builder
public class User {
private int id;
private String name;
private String pass;
private String email;
private String age;
public User(int id, String name, String pass, String email, String age) {
this.id = id;
this.name = name;
this.pass = pass;
this.email = email;
this.age = age;
}
}
generated class, the compiler did the rest for us to avoid boilerplates and repeated codes.
public class User_Builder {
private int id;
private String name;
private String pass;
private String email;
private String age;
public User_Builder() {
}
public User_Builder setId(int id) {
this.id = id;
return this;
}
public User_Builder setName(String name) {
this.name = name;
return this;
}
public User_Builder setPass(String pass) {
this.pass = pass;
return this;
}
public User_Builder setEmail(String email) {
this.email = email;
return this;
}
public User_Builder setAge(String age) {
this.age = age;
return this;
}
public User build() {
return new User(id,name,pass,email,age);
}
}
User user = new User_Builder()
...
.setName("Ali")
.setEmail("ali@gmail.com")
.build();
- ANNOTATION PROCESSING 101 - by Hannes Dorfmann
- DroidconDE 2015: Annotation Processing 101 - by Hannes Dorfmann (VIDEO)
- Annotation Processing : Don’t Repeat Yourself, Generate Your Code
- Annotation processing basics
- Annotation Processing for Android
MIT License
Copyright (c) 2018 Ali Esa Assadi