package com.mc.bsfram.others.entity; public class Person { private String name; private String address; private int age; private double salarry; public String getName() { return name; } public void setName(String name) { this.name = name; } public St
我们在构建一个MAP时,要不停的调用put,有时候看着觉得很麻烦,刚好,看了下builder模式,觉得这思路不错,于是乎,照着用builder模式写了一个构建MAP的示例,代码如下: import java.util.HashMap; import java.util.Map; public class MapBuilder<T> { public Builder<T> b; public MapBuilder(Builder<T> b){ this.b = b; }
package com.geostar.gfstack.operationcenter.logger.manager.common; /** * Created by Nihaorz on 2017/8/14. */ public class DBConfig { private String driver; private String url; private String username; private String password; public static class Buil
Builder 优雅的链式调用来实现实例化对象 1. 首先在实体类中,构造一个Builder内部类,由Builder来完成Person的属性赋值,并最终执行build来完成Person的实例化 package com.example.entity; /** * @author: GuanBin * @date: Created in 下午7:20 2019/5/26 */ public class Person { private final String name; private Stri
builder模式在越来越多的项目中使用,类似于alibaba fastjson JSONObject.fluentPut(),调用一个方法后返回这个对象本身,特别适合构建一些参数超级多的对象,代码优雅且易读.构建一个对象变成了SomeObject some = new SomeObject().a("a").b("b").c("c").biuld();.ItellJ IDEA和Eclipse的generator只能生成传统的getter set