Java链式写法
2020-12-13 15:37
标签:img bsp html int 解析 info pac tle package Java 链式写法:详细看代码 打印结果: Java链式写法 标签:img bsp html int 解析 info pac tle package 原文地址:https://www.cnblogs.com/fanerwei222/p/11613067.html原创:转载需注明原创地址 https://www.cnblogs.com/fanerwei222/p/11613067.html
package chain;
/**
* TODO
* 解析器
*/
public class Parser {
private String id;
private String mode;
private String concatIdMode;
public static Parser parse(){
return new Parser();
}
public Parser setParserId(String id){
this.id = id;
return this;
}
public Parser setParserMode(String mode){
this.mode = mode;
return this;
}
public Parser concat(){
this.concatIdMode = "id: " + this.id + " " + "模式 : " + this.mode;
return this;
}
public String print(){
System.out.println("解析器的id和模式为: " + this.concatIdMode);
return this.concatIdMode;
}
}
package chain;
/**
* TODO
* 链式
*/
public class Chains {
public static void main(String[] args) {
String concat = Parser.parse()
.setParserId("12")
.setParserMode("dev")
.concat()
.print();
System.out.println(concat);
}
}