饿汉式:
- class Single
- {
- private static final Single s = new Single();
- private Single(){}
- public static Single getInstance()
- {
- Return s;
- }
- }
复制代码
懒汉式
- Class Single
- {
- private static Single s = null;
- private Single(){}
- public static Single getInstance()
- {
- If(s = null)
- s = new Single();
- return s;
- }
- }
复制代码
方便查看所用。 |
|