单例模式,你看看Runtime的源代码就可以了。
Runtime的构造函数是私有的,从程序角度也不允许你直接创建。
从深层次考虑,如果你的Runtime可以随你创立,那JAVA程序的安全性将会大为降低。
建议你多了解点单例模式。类似的还有Calendar.getInstance()
public class Runtime {
private static Runtime currentRuntime = new Runtime();
/**
* Returns the runtime object associated with the current Java application.
* Most of the methods of class <code>Runtime</code> are instance
* methods and must be invoked with respect to the current runtime object.
*
* @return the <code>Runtime</code> object associated with the current
* Java application.
*/
public static Runtime getRuntime() {
return currentRuntime;
}
/** Don't let anyone else instantiate this class */
private Runtime() {} |