本月博客排行
-
第1名
wy_19921005 -
第2名
mft8899 -
第3名
benladeng5225 - duanfei
- Anmin
- wddpwzzhao123
年度博客排行
-
第1名
龙儿筝 -
第2名
宏天软件 -
第3名
wy_19921005 - benladeng5225
- vipbooks
- kaizi1992
- tanling8334
- sam123456gz
- arpenker
- zysnba
- fantaxy025025
- xiangjie88
- wallimn
- e_e
- jh108020
- ganxueyun
- Xeden
- xyuma
- wangchen.ily
- zhanjia
- johnsmith9th
- zxq_2017
- forestqqqq
- jbosscn
- daizj
- xpenxpen
- 喧嚣求静
- kingwell.leng
- lchb139128
- kristy_yy
- 青否云后端云
- javashop
- lzyfn123
- sunj
- yeluowuhen
- ajinn
- lerf
- lemonhandsome
- chenqisdfx
- xiaoxinye
- lyndon.lin
- flashsing123
- bosschen
- zhangjijun
- sunnylocus
- lyj86
- paulwong
- sgqt
- hudiemeng870329
- mft8899
最新文章列表
java对象的创建建议
1.1 考虑用静态工厂方法代替构造器
示例:
public static Boolean valueOf()boolean b {
return b ? Boolean.TRUE : Boolean.FALSE;
}
静态工厂方法的优势:
1、相对于构造器,静态工厂方法有名称。
例如:构造器BigInteger(int,int,Random)返回的BigInteger可能为素数 ...
EJ.02 遇到多个构造器参数时要考虑用构建器
重叠构造器(telescoping constructor)模式 —— 代码复杂,阅读困难
示例代码:
// Telescoping constructor pattern - does not scale well!
public class NutritionFacts {
private final int servingSize; // (ml) required
...