All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jfaster.badger.util.Reflections Maven / Gradle / Ivy

package org.jfaster.badger.util;

import org.jfaster.badger.exception.BeanInstantiationException;

/**
 *
 * @author yanpengfang
 * create 2019-01-07 6:31 PM
 */
public class Reflections {
    public static  T instantiate(Class clazz) throws BeanInstantiationException {
        if (clazz.isInterface()) {
            throw new BeanInstantiationException(clazz, "specified class is an interface");
        }
        try {
            return clazz.newInstance();
        } catch (InstantiationException e) {
            throw new BeanInstantiationException(clazz, "Is it an abstract class?", e);
        } catch (IllegalAccessException e) {
            throw new BeanInstantiationException(clazz, "Is the constructor accessible?", e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy