Java基礎 Runtime 用了單例模式中的餓漢式
阿新 • • 發佈:2017-10-09
face ring lang run ice ffi new es2017 obj
禮悟:
好好學習多思考,尊師重道存感恩。葉見尋根三返一,活水清源藏於零。
虛懷若谷良心主,皓月當空自在王。願給最苦行無悔,誠勸且行且珍惜。
os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)
源碼(僅提取出能顯示出單例模式-餓漢式 特征性的代碼):
/* * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.lang; import java.io.*; import java.util.StringTokenizer; import sun.reflect.CallerSensitive; import sun.reflect.Reflection; /** * 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 * @see java.lang.Runtime#getRuntime() * @since JDK1.0 */ 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() {}
源碼分析:
API:
Java優秀,值得學習。
設計模式中蘊含著極高的智慧,對項目開發有大幫助。
學習資源:itcast和itheima視頻庫。如果您有公開的資源,可以分享給我的話,用您的資源學習也可以。
博文是觀看視頻後,融入思考寫成的。博文好,是老師講得好。博文壞,是 給最苦 沒認真。
Java基礎 Runtime 用了單例模式中的餓漢式