首页 > 编程语言 > 详细

Java链式写法

时间:2019-09-30 17:37:19      阅读:98      评论:0      收藏:0      [点我收藏+]
原创:转载需注明原创地址 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链式写法

原文:https://www.cnblogs.com/fanerwei222/p/11613067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!