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; } } }  static Class<?> calculateCommonSuperType(Class<?>... types); static Class<?> calculateCommonSuperType(Class<?> first,
            Class<?> second); static Class<?> getGuaranteedBoxedVersion(Class<?> type);  }
@Test public void testCommonSuperType() { assertEquals(Number.class, ClassUtils.calculateCommonSuperType(Byte.class, Integer.class)); assertEquals(Number.class, ClassUtils.calculateCommonSuperType(double.class, Integer.class)); assertEquals(Integer.class, ClassUtils.calculateCommonSuperType(int.class, Integer.class)); assertEquals(Object.class, ClassUtils.calculateCommonSuperType(Byte.class, String.class)); }