public TestBuildObject build() {
TestBuildObject obj = new TestBuildObject(this.id, this.name, this.address);
return obj;
public int getId() {
return id;
public String getName() {
return name;
public String getAddress() {
return address;
@Override
public String toString() {
return "TestBuildObject [id=" + id + ", name=" + name + ", address=" + address + "]";
//测试示例
package testBuildObj;
public class TestBuildObjMain {
public static void main(String[] args) {
TestBuildObject obj = TestBuildObject.newBuilder().id(12).name("Tom").address("Pandora").build();
System.out.println(obj);
TestBuildObject obj2 = TestBuildObject.newBuilder().name("Jerry").build();
System.out.println(obj2);