lombok骚操作
@Slf4j、@Getter、@Data、@AllArgsConstructor、@ToString
@Slf4j
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Data
@ToString
Builder 建造者
import lombok.Builder;
import lombok.Singular;
import lombok.ToString;
import java.util.List;
public class Test {
@Builder
@ToString
public static class Student {
private String name;
private Integer age;
@Singular("addHobby")
private List<String> hobby;
}
public static void main(String[] args) {
Student student = Student.builder ()
.name ("ding")
.age (20)
.addHobby ("play")
.build ();
System.out.println (student);
}
}
@SneakyThrows、@Cleanup
@SneakyThrows
public static void main(String[] args) {
@Cleanup FileInputStream fis = new FileInputStream ("sd");
}
@Accessors(chain = true) 链式调用
@Data
@Accessors(chain = true)
class User {
private String name;
private int age;
private String email;
public static void main(String[] args) {
User user = new User ();
user.setName ("d").setAge (1).setEmail ("545@");
System.out.println (user);
}
}
@FieldNameConstants 获取字段名的常量
@Data
@Accessors(chain = true)
@FieldNameConstants
class User {
private String name;
private int age;
private String email;
public static void main(String[] args) {
System.out.println (User.Fields.age);
System.out.println (User.Fields.name);
}
}