设计模式:单例模式在JDK中的应用
生活随笔
收集整理的這篇文章主要介紹了
设计模式:单例模式在JDK中的应用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在java jdk中, java.lang.Runtime就是經(jīng)典的單例模式。
? 以下截取Runtime部分代碼
package java.lang;import java.io.*; import java.util.StringTokenizer;/*** Every Java application has a single instance of class * <code>Runtime</code> that allows the application to interface with * the environment in which the application is running. The current * runtime can be obtained from the <code>getRuntime</code> method. * <p>* An application cannot create its own instance of this class. ** @author unascribed* @version %I%, %G%* @see java.lang.Runtime#getRuntime()* @since JDK1.0*/public class Runtime {private static Runtime currentRuntime = new Runtime();public static Runtime getRuntime() { return currentRuntime;}/** Don't let anyone else instantiate this class */private Runtime() {} }?
總結(jié)
以上是生活随笔為你收集整理的设计模式:单例模式在JDK中的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式:单例模式之枚举
- 下一篇: 设计模式:原型模式