Contents

Views 12544 Comment 0
Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

싱글톤 패턴 간단 예제

import java.util.HashMap;

class Singleton {
    private static HashMap map = new HashMap();
    //private static Logger logger = Logger.getRootLogger();

    protected Singleton() {
        // Exists only to thwart instantiation
    }

    public static synchronized Singleton getInstance(String classname) {
        Singleton singleton = (Singleton)map.get(classname);
        if(singleton != null) {
            System.out.println("got singleton from map: " + singleton);
            return singleton;
        }
        try {
            singleton = (Singleton)Class.forName(classname).newInstance();
        }
        catch(ClassNotFoundException cnf) {
            System.out.println("Couldn't find class " + classname);     
        }
        catch(InstantiationException ie) {
            System.out.println(
            "Couldn't instantiate an object of type " + classname);
        }
        catch(IllegalAccessException ia) {
            System.out.println("Couldn't access class " + classname);     
        }
        map.put(classname, singleton);
        System.out.println("created singleton: " + singleton);
        return singleton;
    }
}

class SingletonTest {
    public static void main(String[] args) {
    }
}


?

  1. [ios] XCode에서 Provisioning Profile 여러개 중복될 때

  2. 알고리즘 성능 분석 기준

  3. 알고리즘 성능분석

  4. [ios] iOS에서 디바이스 종류 알아오기

  5. [ios] 아이폰 GPS 사용하기

  6. [ios] 언어, 지역, 국가 설정 가져오기

  7. [ios] URL 파라미터 파싱~

  8. [ios] 앱 딜리게이트 얻어오기. (AppDelegate)

  9. [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle)

  10. [ios] 애플 앱스토어 IDFA 리뷰 정책 변경 안내

  11. [ios] NSString URL Encode/Decode (인코딩/디코딩)

  12. [ios] 커스텀 폰트 사용하기 (Custom Fonts)

Board Pagination Prev 1 ... 11 12 13 14 15 16 17 18 19 20 ... 71 Next
/ 71