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() {}作者: 匿名 时间: 2011-7-27 18:54 标题: 回复 楼主 的帖子 这是一个单例模式,Runtime的构造函数是private,那是不能new的作者: 匿名 时间: 2011-7-27 22:57
Runtime类封装了运行时的环境。每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接。既然是运行时类实例,一旦程序运行就说明已经有这个实例对象了为啥还要再new实例对象呢.