原创:转载需注明原创地址 https://www.cnblogs.com/fanerwei222/p/11613067.html

 

Java 链式写法:详细看代码

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);
    }
}

打印结果:

Java链式写法

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-03-01
  • 2021-09-28
  • 2022-01-21
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案