ClassUtils { static boolean canAssign(Class<?> baseClass, Class<?> classToCheck) { if (baseClass.isAssignableFrom(classToCheck)) { return true; } else { if (baseClass.isPrimitive()) { Class primitiveClass = PRIMITIVE_WRAPPERS.get(classToCheck); if (primitiveClass != null) { return baseClass.isAssignableFrom(primitiveClass); } } else if (classToCheck.isPrimitive()) { Class primitiveClass = PRIMITIVE_WRAPPERS.get(baseClass); if (primitiveClass != null) { return primitiveClass.isAssignableFrom(classToCheck); } } } return false; }    }
@Test public void testCanAssignTwoAnyObjects() throws Exception { assertTrue(ClassUtils.canAssign(String.class, String.class)); }
@Test public void testCanAssignTwoAnyObjectsWithHierarchy() throws Exception { assertTrue(ClassUtils.canAssign(AnyClass.class, SonOfAnyClass.class)); }
@Test public void testCanAssignTwoObjectsWithAPrimitiveObject() throws Exception { assertTrue(ClassUtils.canAssign(int.class, Integer.class)); }
@Test public void testCanAssignTwoObjectsWithAPrimitiveObjectBase() throws Exception { assertTrue(ClassUtils.canAssign(Integer.class, int.class)); }