Effective Java Item3:Enforce the singleton property with a private constructor or an enum type
Item3:Enforce the singleton property with a private constructor or an enum type
采用枚举类型(ENUM)实现单例模式。
public enum Elvis {
INSTANCE; public void leaveTheBuiding(){
System.out.println("a single-element enum type is the best way to implement a singleton");
}
}
使用方式:
Elvis.INSTANCE.leaveTheBuiding();
Effective Java Item3:Enforce the singleton property with a private constructor or an enum type的更多相关文章
- Effective Java 03 Enforce the singleton property with a private constructor or an enum type
Principle When implement the singleton pattern please decorate the INSTANCE field with "static ...
- Java之创建对象>3.Enforce the singleton property with a private constructor or an enum type
1. 通过一个公开的字段来获取单例 // Singleton with public final field public class Elvis { public static final Elv ...
- Effective Java Item4:Enforce noninstantiability with a private constructor
Item4:Enforce noninstantiability with a private constructor 通过构造私有化,禁止对象被实例化. public class UtilClass ...
- Effective Java 04 Enforce noninstantiability with a private constructor
A class can be made noninstantiable by including a private constructor. // Noninstantiable utility c ...
- Effective Java 02 Consider a builder when faced with many constructor parameters
Advantage It simulates named optional parameters which is easily used to client API. Detect the inva ...
- Effective Java Item2:Consider a builder when faced with many constructor parameters
Item2:Consider a builder when faced with many constructor parameters 当构造方法有多个参数时,可以考虑使用builder方式进行处理 ...
- Effective Java Index
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st langu ...
- Effective Java 目录
<Effective Java>目录摘抄. 我知道这看起来很糟糕.当下,自己缺少实际操作,只能暂时摘抄下目录.随着,实践的增多,慢慢填充更多的示例. Chapter 2 Creating ...
- 【Effective Java】阅读
Java写了很多年,很惭愧,直到最近才读了这本经典之作<Effective Java>,按自己的理解总结下,有些可能还不够深刻 一.Creating and Destroying Obje ...
随机推荐
- IBM Cognos 10 启动报错
报错信息: 15:35:02, 'LogService', 'StartService', 'Success'. 15:35:03, CAF input validation enabled. 15: ...
- [转载]memcached stats 命令
STAT pid 1552 STAT uptime 3792 STAT time 1262517674 STAT version 1.2.6 STAT pointer_size 32 STAT cur ...
- BZOJ1640: [Usaco2007 Nov]Best Cow Line 队列变换
1640: [Usaco2007 Nov]Best Cow Line 队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 493 Solved: 2 ...
- linux串口驱动分析——发送数据
一.应用程序中write函数到底层驱动历程 和前文提到的一样,首先先注册串口,使用uart_register_driver函数,依次分别为tty_register_driver,cdev_init函数 ...
- codevs1906 最长递增子序列问题
题目描述 Description 给定正整数序列x1,..... , xn .(1)计算其最长递增子序列的长度s.(2)计算从给定的序列中最多可取出多少个长度为s的递增子序列.(3)如果允许在取出的 ...
- poj2955:括号匹配,区间dp
题目大意: 给一个由,(,),[,]组成的字符串,其中(),[]可以匹配,求最大匹配数 题解:区间dp: dp[i][j]表示区间 [i,j]中的最大匹配数 初始状态 dp[i][i+1]=(i,i+ ...
- vi查找
/pattern<Enter> :向下查找pattern匹配字符串 ?pattern<Enter>:向上查找pattern匹配字符串 使用了查找命令之后,使用如下两个键快速查找 ...
- Android笔记(二):从savedIndstanceState发散
savedIndstanceState savedIndstanceState位于ActivityonCreate(Bundle savedInstanceState)方法的参数中.对这个参数的理解要 ...
- mysql中文名字按首字母排序
在mysql数据库中可以使用GBK编码对中文进行排序,如名字按首字母排序 order by convert(substr(tu.username,1,1) using 'GBK') 其中substr方 ...
- Gulp:静态资源(css,js)版本控制
为了防止客户端的静态资源缓存,我们需要每次更新css或js的时候,通过md5或时间戳等方式重新命名静态资源: 然后涉及到的html模板里的src也要做相应的修改,静态资源需要优化(压缩合并) 文件目录 ...