• java的多构造函数的处理方式


    /**
     * 
     */
    package P;
    
    import java.awt.List;
    import java.lang.reflect.Array;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Date;
    import java.util.GregorianCalendar;
    import java.util.HashMap;
    
    import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
    
    import S.Smty;
    
    /**
     * @author Administrator
     *
     */
    public class Q {
    
    	
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		Person p =new Person.Builder("mike").setAge(14).build();
    		
    		System.out.println(p.getName());
    		System.out.println(p.getAge());
    	}
    	
    	
    }
    
    
    class Person {
    	private String name;
    	private int age;
    	
     	public static class Builder{
     		private String name=null;
     		private int age=0;
     		
     		public Builder(String name){
     			this.name=name;
     			
     		}
     		
     		public Builder setAge(int age) {
     			this.age=age;
     			return this;
     		}
     		
     		public Person build() {
     			return new Person(this);
     		}
     	}
     	
     	public Person(Builder builder) {
     		this.name=builder.name;
     		this.age=builder.age;
     	}
     	
     	public String getName() {
    		return name;
    	}
     	public int getAge() {
    		return age;
    	}
    }
    

      

  • 相关阅读:
    Day4 0708
    Day2 0706
    两道递推公式题的解题报告
    博客还需优化
    飞行路线Luogu4568
    堆优化Dijkstra(Luogu 4779)
    2019四等奖的清明节征文
    2019四等奖的叶圣陶初稿
    Luogu P1072 Hankson的趣味题
    Loj10022 埃及分数(迭代加深搜索IDDFS)
  • 原文地址:https://www.cnblogs.com/norm/p/8135728.html
Copyright © 2020-2023  润新知