common_helper/src/main/java/com/xiongyingqi/util/EntityHelper.java
public static final <T> T getSingleton(Class<T> clazz, Object... args) throws Exception {
        T instance = null;
        synchronized (LOCK) {
            instance = (T) singletonMap.get(clazz);
            if (instance == null) {
                Constructor<?> constructor = null;
                try {
                    constructor = getConstructor(clazz, args);
                } catch (SecurityException e1) {
                } catch (NoSuchMethodException e1) {
                }
                if (constructor != null) {
                    try {
                        instance = (T) constructor.newInstance(args);
                    } catch (IllegalArgumentException e) {
                    } catch (InstantiationException e) {
                    } catch (IllegalAccessException e) {
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
                if (instance == null) {
                    Constructor<?>[] constructors = clazz.getConstructors();
                    for (int i = 0; i < constructors.length; i++) {
                        Constructor<?> constructorVar = constructors[i];
                        try {
                            instance = (T) constructorVar.newInstance(args);
                        } catch (IllegalArgumentException e) {
                        } catch (InstantiationException e) {
                        } catch (IllegalAccessException e) {
                        } catch (InvocationTargetException e) {
                        }
                    }
                }
                if (instance == null) {
                    throw new NoSuchMethodException("无法初始化对象: " + clazz + "; 请检查传入的参数是否吻合");
                }
            }
            singletonMap.put(clazz, instance);
        }
        return instance;
    }
public static final <T> T getSingleton(Class<T> clazz, Object... args) throws Exception {
        T instance = null;
        synchronized (LOCK) {
            instance = (T) singletonMap.get(clazz);
            if (instance == null) {
                Constructor<?> constructor = null;
                try {
                    constructor = getConstructor(clazz, args);
                } catch (SecurityException e1) {
                } catch (NoSuchMethodException e1) {
                }
                if (constructor != null) {
                    try {
                        instance = (T) constructor.newInstance(args);
                    } catch (IllegalArgumentException e) {
                    } catch (InstantiationException e) {
                    } catch (IllegalAccessException e) {
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
                if (instance == null) {
                    Constructor<?>[] constructors = clazz.getConstructors();
                    for (int i = 0; i < constructors.length; i++) {
                        Constructor<?> constructorVar = constructors[i];
                        try {
                            instance = (T) constructorVar.newInstance(args);
                        } catch (IllegalArgumentException e) {
                        } catch (InstantiationException e) {
                        } catch (IllegalAccessException e) {
                        } catch (InvocationTargetException e) {
                        }
                    }
                }
                if (instance == null) {
                    throw new NoSuchMethodException("无法初始化对象: " + clazz + "; 请检查传入的参数是否吻合");
                }
            }
            singletonMap.put(clazz, instance);
        }
        return instance;
    }
public static final < T > T getSingleton ( Class < T > clazz , Object ... args ) throws Exception { T instance = null ; synchronized ( LOCK ) { instance = ( T ) singletonMap . get ( clazz ) ; if ( instance == null ) { Constructor < ? > constructor = null ; try { constructor = getConstructor ( clazz , args ) ; } catch ( SecurityException e1 ) { } catch ( NoSuchMethodException e1 ) { } if ( constructor != null ) { try { instance = ( T ) constructor . newInstance ( args ) ; } catch ( IllegalArgumentException e ) { } catch ( InstantiationException e ) { } catch ( IllegalAccessException e ) { } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } } if ( instance == null ) { Constructor < ? > [ ] constructors = clazz . getConstructors ( ) ; for ( int i = 0 ; i < constructors . length ; i ++ ) { Constructor < ? > constructorVar = constructors [ i ] ; try { instance = ( T ) constructorVar . newInstance ( args ) ; } catch ( IllegalArgumentException e ) { } catch ( InstantiationException e ) { } catch ( IllegalAccessException e ) { } catch ( InvocationTargetException e ) { } } } if ( instance == null ) { throw new NoSuchMethodException ( "无法初始化对象: " + clazz + ";  检 传入的参数 否 合"); } } singletonMap . put ( clazz , instance ) ; } return instance ; }
获取Class类的单例，如果其他类不是使用的该方法，那么必定造成对象引用不一致！因此一定要检查每个对象的构造方式是否一致都是使用本方法来构造 <br>
2013-10-21 上午11:22:55

@param clazz 类型
@param args  构造函数的参数列表
@return 单例对象
@throws Exception 异常
获取Class类的单例，如果其他类不是使用的该方法，那么必定造成对象引用不一致！因此一定要检查每个对象的构造方式是否一致都是使用本方法来构造 <br > 2013 - 10 - 21 上午11 : 22 : 55