JDKでのシングルトンパターンの応用

いくつかの単語の男は、直接ソースコードを、言いました

ランタイムクラスのシングルトンパターンを使用します:

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.
     */
     //在方法中调用创建好的静态方法currentRuntime
    public static Runtime getRuntime() {
        return currentRuntime;
    }

    /** Don't let anyone else instantiate this class */
    private Runtime() {}

公開された47元の記事 ウォン称賛34 ビュー8856

おすすめ

転載: blog.csdn.net/weixin_42893085/article/details/105413853