Bootstrap

JavaBeen类的几种写法及优缺点

一、重载构造方法的JavaBeen

        先写一个必选的构造,然后写一个必选加一个可选构造,接着写一个必选加两个可选的构造,一次类推,如下user类

public class User {
    private final String mFirstName;//必选
    private final String mLastName;//必选
    private final String mGender;//可选
    private final int mAge;//可选
    private final String mPhoneNumber;//可选


    public User(String firstName , String lastName) {
        this(firstName , lastName , "");
    }



    public User(String firstName , String lastName , String gender) {
        this(firstName , lastName , gender , 0);
    }


    public User(String firstName , String lastName ,  String gender , int age) {
        this(firstName , lastName , gender , age , "");
    }

    public User(String firstName , String lastName,  String gender , int age , String phoneNumber) {
        mFirstName = firstName;
;