setter 和 getter 的构建器

我想使用此 Java 代码来创建 Java 对象:


public class NotificationMessage implements Serializable {


    private static final long serialVersionUID = 985577913631100757L;


    private int id;

    private String uniqueid;

    private String status;

    private String type;

    private Map<String, String> map;

    private Date created_at;


    public NotificationMessage() {

    }


    public NotificationMessage(int id, String uniqueid, String status, String type, Map<String, String> map,

            Date created_at) {

        this.id = id;

        this.uniqueid = uniqueid;

        this.status = status;

        this.type = type;

        this.map = map;

        this.created_at = created_at;

    }


    public int getId() {

        return id;

    }


    public void setId(int id) {

        this.id = id;

    }

....

}

当我想创建 Java 对象时,如何使用构建器来最小化设置器?


我想设置这样的值:


NotificationMessage.builder().id(123).uniqueid(1234).status("active")


慕姐8265434
浏览 128回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java