Effective Java Item3:Enforce the singleton property with a private constructor or an enum type
2015-02-25 13:09
363 查看
Item3:Enforce the singleton property with a private constructor or an enum type
采用枚举类型(ENUM)实现单例模式。
使用方式:
采用枚举类型(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 英文 第二版 读书笔记 Item 3:Enforce the singleton property with a private constructor or an enum type.
- Java之创建对象>3.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
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- Effective Java 04 Enforce noninstantiability with a private constructor
- java编译错误No enclosing instance of type TestFrame is accessible. Must qualify the allocation with an enclosing instance of type TestFrame (e.g. x.new A(
- Specified ID:supplyItemLocalDS collides with the ID for an existing SmartGWT component or object.
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Bean property 'RegDao' is not writable or has an invalid setter method. Does the parameter type of t
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleT
- The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- <java>No enclosing instance of type GraphicFrame is accessible. Must qualify the allocation with an
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleT