class ClassUtils {

    public static Class<?> calculateCommonSuperType(Class<?>... types) {
        switch (types.length) {
            case 0:
                return null;
            case 1:
                return types[0];
            case 2:
                return calculateCommonSuperType(types[0], types[1]);
            default: {
                Class<?> common = types[0];
                for (int i = 1; i < types.length; i++) {
                    if (common == java.lang.Object.class) {
                        break;
                    }
                    common = calculateCommonSuperType(common, types[i]);
                }
                return common;
            }
        }
    }

}