zoukankan      html  css  js  c++  java
  • Java Instance return model note!

    1. We have a class and define a static method of  getInstance()
     
    public class GenDarwinGlobal extends GenDarwinGlobalHelper
    {
        
    /**
         * Script Name   : <b>GenDarwinGlobal</b>
         * Generated     : <b>Mar 31, 2011 1:16:48 AM</b>
         * Description   : Functional Test Script
         * Original Host : WinNT Version 5.2  Build 3790 (S)
         * 
         * 
    @since  2011/03/31
         * 
    @author dwei
         
    */
        
    public void testMain(Object[] args) 
        {
            
    // TODO Insert code here
        }
        
    public  static GenDarwinGlobal getInstance()
        {
            
    return new GenDarwinGlobal();
        }
    }
     
    2. Compare these code line, the getInstance sequence will get failed return because it has two new instance belong to different object.
    //        FucLib.GenevaFuc.GenDarwinGlobal.getInstance().openBuyTransaction();
        
    //    FucLib.GenevaFuc.GenDarwinGlobal.getInstance().ClickQuery();
            
            
            FucLib.GenevaFuc.GenDarwinGlobal oGD 
    =  new FucLib.GenevaFuc.GenDarwinGlobal(); 
            oGD.openBuyTransaction();
            oGD.ClickQuery();
    3. Also we can using this method to resolve this problem in the instance code .
     
    private static GenDarwinGlobal instance = null;
    public static synchronized GenDarwinGlobal getInstance()
    {
       
    if( instance == null)
       {
        instance 
    = new GenDarwinGlobal();
       }
        
    return instance;
    }
     
     
  • 相关阅读:
    javascript箭头函数把函数给简写了[0403]
    BootStrap实现左侧或右侧竖式tab选项卡
    对回调函数的理解
    全屏滚动插件之 fullpage.js
    网页的缩放,适配以及移动的适配!
    Vue组件通信(传值)
    深入理解ES6之迭代器与生成器
    用css完成根据子元素不同书写样式
    简书上写博客感觉更爽点
    自定义View系列教程03--onLayout源码详尽分析
  • 原文地址:https://www.cnblogs.com/zencorn/p/2043294.html
Copyright © 2011-2022 走看看