《Effective Java》builder模式创建对象
来源:互联网 发布:成考与网络教育 编辑:程序博客网 时间:2024/05/29 03:36
package com.base.test;/** * * @author ZHEN.L * @DATE 2016.04.22 * */public class StudentDto {private String name;private int age;private String address;private StudentDto() {}public static class Build {private StudentDto s = new StudentDto();public Build name(String name) {this.s.setName(name);return this;}public Build age(int age) {this.s.setAge(age);return this;}public Build address(String address) {this.s.setAddress(address);return this;}public StudentDto build() {return s;}}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 getAddress() {return address;}public void setAddress(String address) {this.address = address;}}
import com.base.test.StudentDto;public class Test {<span style="white-space:pre"></span>public static void main(String[] args) {<span style="white-space:pre"></span>StudentDto s = new StudentDto.Build().name("张三").age(18).address("复兴路")<span style="white-space:pre"></span>.build();<span style="white-space:pre"></span>System.out.println(s.getName() + " : " + s.getAge() + " : "<span style="white-space:pre"></span>+ s.getAddress());<span style="white-space:pre"></span>}}
0 0
- 《Effective Java》builder模式创建对象
- effective java之Buileder模式创建对象
- Builder模式创建对象
- effective java之 builder模式
- Effective Java --- 创建对象
- 创建对象之Builder模式
- 【Effective Java】Ch2_创建销毁对象:Item2_当构造函数参数过多时考虑使用builder
- 《Effective Java》单例模式创建多对象
- builder模式-对象创建型模式
- Java创建对象(重叠构造器模式,javaBean模式,Builder模式)
- Builder(生成器)---对象创建型模式
- javascript 对象创建模式 之 builder
- 《Effective Java》Builder
- 学习effective java-2创建和销毁对象之当类有多个构造参数时,请考虑使用一个builder来创建对象
- 设计模式(5)-对象创建型模式-Builder模式
- 设计模式(5)-对象创建型模式-Builder模式
- Effective Java(02)创建和销毁对象
- effective java(创建和销毁对象)
- 第一篇博客
- 判断两条线段是否相交
- iOS学习笔记69-再细读KVO
- 前端性能优化-减少重绘
- 约瑟夫问题(Josephus problem)
- 《Effective Java》builder模式创建对象
- filter过滤器 和拦截器的区别?
- 杭电1465
- iOS学习笔记70-使用NSURLConnection实现文件上传
- UVa 11059 Maximum Product
- php pack、unpack、ord 函数使用方法(二进制流接口应用实例)
- Mybatis最入门---动态查询(choose,when,otherwise)
- css复习 - 伪类,伪元素
- spring 标签:context:property-placeholder