zoukankan      html  css  js  c++  java
  • 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;
    	}
    }
    

      

  • 相关阅读:
    Type Safety and Type Inference
    LEARN SWIFT
    swift 类型备份
    Swift
    associatedtype关联类型
    深入理解 Swift 派发机制
    Swift中self和Self
    Postfix Self Expression
    CGContext与上下文
    eeee
  • 原文地址:https://www.cnblogs.com/norm/p/8135728.html
Copyright © 2011-2022 走看看