java内部静态类返回外部类对象的范例

package com.alibaba;

class Extenal {
    private String name;
    private int age;
    private String action;
    public Extenal(Buider buider){
        this.name=buider.name;
        this.age=buider.age;
        this.action=buider.action;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public static class Buider {
        String name;
        int age;
        String action;

        public Buider name(String name) {
            this.name = name;
            return this;
        }

        public Buider age(int age) {
            this.age = age;
            return this;
        }

        public Buider action(String action) {
            this.action = action;
            return this;
        }
        public Extenal build(){
            return new Extenal(this);
        }
    }

    @Override
    public String toString() {
        return "JavaStatic{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", action='" + action + '\'' +
                '}';
    }

}
class testaa{
    public static void main(String[] args) {
        Extenal javaStatic = new Extenal.Buider()
                .age(100)
                .name("重置")
                .action("测试题")
                .build();
        System.out.println(javaStatic);
    }
}

 

posted on 2022-03-29 19:49  jiapengchu  阅读(186)  评论(0编辑  收藏  举报

导航