构造参数的一个方法

 


package com.nbad.test;

public class TestBean {
	private String name;
	private String age;

	public TestBean() {
		this(new Build());
	}

	public TestBean(Build build) {
		this.name = build.name;
		this.age = build.age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "TestBean [name=" + name + ", age=" + age + "]";
	}

	public static final class Build {

		public String name;
		public String age;

		public Build() {

		}

		public Build setName(String name) {
			this.name = name;
			return this;
		}

		public Build setAge(String age) {
			this.age = age;
			return this;
		}

		public TestBean build() {
			return new TestBean(this);
		}
	}

}