概念
所谓链式,也就是每次调用对象方法后返回的都是该对象本身,而该对象又可以继续调用方法。
例子
public class Demo {
private String path;
private Map<String, Object> data;
public Demo(String path) {
this.path = path;
data = new HashMap<String, Object>();
}
public Demo data(String key, Object value) {
data.put(key, value);
return this;
}
public String getPath() {
return path;
}
public Map<String, Object> getData() {
return data;
}
public void setData(Map<String, Object> data) {
this.data = data;
}
public static void main(String[] args) {
Demo demo = new Demo("12").data("12","12");
System.out.println(demo.getData());
}
}
网友评论