码迷,mamicode.com
首页 > 其他好文 > 详细

Lombok(1.14.8) - @NoArgsConstructor & @AllArgsConstructor

时间:2015-08-01 01:04:18      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

@NoArgsConstructor

@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

@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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!