Java基础 Runtime 用了单例模式中的饿汉式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java基础 Runtime 用了单例模式中的饿汉式相关的知识,希望对你有一定的参考价值。
礼悟:
好好学习多思考,尊师重道存感恩。叶见寻根三返一,活水清源藏于零。
虚怀若谷良心主,皓月当空自在王。愿给最苦行无悔,诚劝且行且珍惜。
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 用了单例模式中的饿汉式的主要内容,如果未能解决你的问题,请参考以下文章