class ReflectionUtil {

    public static <T> T newInstance(final Class<T> clazz) {
        if(clazz.isAnonymousClass() || clazz.isInterface() || clazz.isAnnotation()) {
            throw new RuntimeException("Can not build new instance of an " + clazz.getName());
        }

        T instance = null;
        for(Constructor<?> constructor : clazz.getConstructors()) {
            instance = (T) instantiateWithConstructor(constructor);
            if (isValidInstance(instance)) return instance;
        }

        for(Constructor<?> constructor : clazz.getDeclaredConstructors()) {
            instance = (T) instantiateWithConstructor(constructor);
            if (isValidInstance(instance)) return instance;
        }

        throw new RuntimeException("Could not instantiate class: "+clazz+", no access to constructors.");
    }

}