标签:
@NoArgsConstructor,提供一个无参的构造方法。
package com.huey.hello.bean; import java.util.Date; import lombok.Data; import lombok.NoArgsConstructor; @NoArgsConstructor @Data public class Student { private int studNo; private String studName; private Date birthday; // 提供了一个含参构造方法,就不会再默认提供无参构造方法 public Student(int studNo, String studName, Date birthday) { super(); this.studNo = studNo; this.studName = studName; this.birthday = birthday; } public static void main(String[] args) { Student stud = new Student(); stud.setStudNo(10001); stud.setStudName("huey"); stud.setBirthday(new Date()); System.out.println(stud); // [OUTPUT]: Student(studNo=10001, studName=huey, birthday=Sat Aug 01 00:03:43 CST 2015) } }
@AllArgsConstructor,提供一个全参的构造方法。
package com.huey.hello.bean; import java.util.Date; import lombok.AllArgsConstructor; import lombok.Data; @AllArgsConstructor @Data public class Student { private int studNo; private String studName; private Date birthday; public static void main(String[] args) { Student stud = new Student(10001, "huey", new Date()); System.out.println(stud); // [OUTPUT]: Student(studNo=10001, studName=huey, birthday=Sat Aug 01 00:03:43 CST 2015) } }
Lombok(1.14.8) - @NoArgsConstructor & @AllArgsConstructor
标签:
原文地址:http://www.cnblogs.com/huey/p/4693484.html