zoukankan      html  css  js  c++  java
  • 单例模式之内部静态类

    1. public class Singleton  
    2. {  
    3.     private Singleton(){ }  
    4.       
    5.     public static Singleton getInstance()  
    6.     {  
    7.         return Nested.instance;       
    8.     }  
    9.       
    10.     //在第一次被引用时被加载  
    11.     static class Nested  
    12.     {  
    13.         private static Singleton instance = new Singleton();  
    14.     }  
    15.       
    16.     public static void main(String args[])  
    17.     {  
    18.         Singleton instance = Singleton.getInstance();  
    19.         Singleton instance2 = Singleton.getInstance();  
    20.         System.out.println(instance == instance2);  
    21.     }  
    22. }  
  • 相关阅读:
    第四次作业
    第三次
    第十次作业
    第九次作业
    第八次作业
    10.29第七次
    15
    14
    13 this
    12 电视机
  • 原文地址:https://www.cnblogs.com/GodZhe/p/4918450.html
Copyright © 2011-2022 走看看