Java Utililty Methods Reflection Assignable

List of utility methods to do Reflection Assignable

Description

The list of methods to do Reflection Assignable are organized into topic(s).

Method

booleanisAssignableFrom(Class toClass, Class fromClass)
is Assignable From
if (toClass == Object.class && !fromClass.isPrimitive()) {
    return true;
if (toClass.isPrimitive()) {
    fromClass = getPrimitiveClassIfWrapper(fromClass);
return toClass.isAssignableFrom(fromClass);
booleanisAssignableValue(Class type, Object value)
Determine if the given type is assignable from the given value, assuming setting by reflection.
return (value != null ? isAssignable(type, value.getClass()) : !type.isPrimitive());
booleanisAssignableValue(Class type, Object value)
Determine if the given type is assignable from the given value, assuming setting by reflection.
if (type == null) {
    throw new IllegalArgumentException("Type must not be null");
return (value != null ? isAssignable(type, value.getClass()) : !type.isPrimitive());
booleanisClassAssignableFrom(Class formal, Class actual)
Indicates whether the formal class is assignable from the actual class, taking into account primitive promotion and auto-boxing semantics.
if (formal == actual) {
    return true;
if (formal.isAssignableFrom(actual)) {
    return true;
if (formal == Object.class) {
    return true;
...
booleanisCompatible(Class actualType, Class parameterType)
is Compatible
if (actualType.isAssignableFrom(parameterType))
    return true;
if (actualType.isPrimitive()) {
    Class wrapperClass = (Class) _primitiveMap.get(actualType);
    return wrapperClass.isAssignableFrom(parameterType);
return false;
booleanisCompatible(Class parameterType, Class parameterClass)
is Compatible
Class wrapperClass = (Class) PRIMITIVE_CLASS_WRAPPERS.get(parameterType);
if (wrapperClass != null) {
    return wrapperClass.isAssignableFrom(parameterClass);
return false;
booleanisCompatible(Class fromClass, Class toClass)
is Compatible
if (fromClass == null || toClass == null) {
    return true;
if (matrixTypePosition.containsKey(fromClass.getName())
        && matrixTypePosition.containsKey(toClass.getName())) {
    return compatibilityMatrix[matrixTypePosition.get(fromClass.getName())][matrixTypePosition
            .get(toClass.getName())];
} else {
...
booleanisCompatible(Class type0, Class type1)
is Compatible
if (type0.getName().equals(type1.getName())) {
    return true;
if (type0.isPrimitive()) {
    return isCompatible(PRIMITIVE_TO_WRAPPER.get(type0), type1);
if (type1.isPrimitive()) {
    return isCompatible(type0, PRIMITIVE_TO_WRAPPER.get(type1));
...
booleanisPromotableFrom(Class assigneeClass, Class valueClass)
Returns true if a variable of a given class can be assigned from a variable of a given class.
assert assigneeClass != null;
assert valueClass != null;
if (assigneeClass.isPrimitive()) {
    Class<?> boxClass = boxTypes.get(assigneeClass);
    assert boxClass != null : "Can't find box type for " + assigneeClass.getName();
    assigneeClass = boxClass;
if (valueClass.isPrimitive()) {
...