class Reflection {

    @SuppressWarnings("unchecked")
    public static <T> T invokeWithDefault(@Nullable Method method, Object obj, T defaultValue,
            @Nullable Object... args) {
        if (method == null) {
            return defaultValue;
        }
        try {
            Object value = method.invoke(obj, args);
            if (value == null) {
                return defaultValue;
            }
            return (T) value;
        } catch (Throwable t) {
            logger.warn("error calling {}.{}()", method.getDeclaringClass().getName(),
                    method.getName(), t);
            return defaultValue;
        }
    }

    private  Reflection();

}