zoukankan      html  css  js  c++  java
  • 单例模式

     1 public class test_test {
     2     private test_test(){}
     3     private static final test_test instance=new test_test();
     4     public static test_test getInstance(){
     5         return instance;
     6     }
     7 
     8 }
     9 
    10 public class test_test{
    11     private test_test(){}
    12     private volatile static  test_test instance=null;
    13     public  static  test_test getInstance(){
    14         if(instance==null){
    15             synchronized(test_test.class){
    16                 if(instance==null){
    17                     return new test_test();                
    18                 }
    19             }            
    20         }
    21     }    
    22 }
    23 
    24 public class test_test{
    25     private test_test(){}
    26     //Java的静态内部类
    27     private static class test_test setInstance(){
    28         private static final test_test instance=new test_test();        
    29     }
    30     public static  test_test getInstance(){
    31         return setInstance.instance;
    32     }
    33 }
    ---- 动动手指关注我!或许下次你又能在我这里找到你需要的答案!ZZZZW与你一起学习,一起进步!
  • 相关阅读:
    CCCC 2020 酱油记
    CCPC 2020 威海 滚粗记
    IEEExtreme 2020 酱油记
    CCSP 2020 酱油记
    ICPC 陕西省赛 2020 游记
    CCPC 网络赛 2020 自闭记
    CSP 第20次认证 酱油记
    CSP-S 2019 酱油记
    NOI2019 退役记
    树链剖分入门
  • 原文地址:https://www.cnblogs.com/zzzzw/p/5055618.html
Copyright © 2011-2022 走看看