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

booleanisAssignable(Class clazz, Class toClass)
is Assignable
if (clazz == null || toClass == null) {
    return false;
if (clazz.equals(toClass)) {
    return true;
Class newClazz = clazz;
Class newToClass = toClass;
...
booleanisAssignable(Class lhsType, Class rhsType)
Check if the right-hand side type may be assigned to the left-hand side type, assuming setting by reflection.
return (lhsType.isAssignableFrom(rhsType) || lhsType.equals(wrapperPrimitives.get(rhsType)));
booleanisAssignable(Class cls, final Class toClass)
is Assignable
if (toClass == null) {
    return false;
if (cls == null) {
    return !toClass.isPrimitive();
if (cls.isPrimitive() && !toClass.isPrimitive()) {
    cls = primitiveToWrapper(cls);
...
booleanisAssignable(Class lhsType, Class rhsType)
is Assignable
return (lhsType.isAssignableFrom(rhsType) || lhsType.equals(primitiveWrapperTypeMap.get(rhsType)));
booleanisAssignable(Class lhsType, Class rhsType)
Check if the right-hand side type may be assigned to the left-hand side type, assuming setting by reflection.
if (lhsType.isAssignableFrom(rhsType)) {
    return true;
if (lhsType.isPrimitive()) {
    Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
    if (lhsType == resolvedPrimitive) {
        return true;
} else {
    Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
    if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) {
        return true;
return false;
booleanisAssignable(Class lhsType, Class rhsType)
Check if the right-hand side type may be assigned to the left-hand side type, assuming setting by reflection.
if (rhsType == null) {
    if (!lhsType.isPrimitive())
        return true;
} else {
    if (lhsType.isAssignableFrom(rhsType))
        return true;
    if (rhsType.isPrimitive() && lhsType.equals(getPrimitiveWrapper(rhsType)))
        return true;
...
booleanisAssignable(final Class from, final Class to)
Determines if the type from is assignable to the type to.
assert from != null;
assert to != null;
if (to.isAssignableFrom(from)) {
    return true;
} else {
    final Class<?> clazz = assignable.get(from);
    return clazz.equals(to);
booleanisAssignableFrom(Class class1, Class class2)
is Assignable From
if (class1.isAssignableFrom(class2))
    return true;
if (!class1.isPrimitive())
    return false;
Class<?> wrapper = primitiveToWrapperClass.get(class1.getName());
return wrapper.isAssignableFrom(class2);
booleanisAssignableFrom(Class to, Class from)
Improves java5's Class.isAssignableFrom method.
if (PRIMITIVE_TO_WRAPPER.get(to) == from || PRIMITIVE_TO_WRAPPER.get(from) == to) {
    return true;
return to.isAssignableFrom(from);
booleanisAssignableFrom(Class to, Class from)
Just like Class.isAssignableFrom(), but does the right thing when considering autoboxing.
Class<?> notPrimitiveTo = to.isPrimitive() ? PRIMITIVE_TO_WRAPPER.get(to) : to;
Class<?> notPrimitiveFrom = from.isPrimitive() ? PRIMITIVE_TO_WRAPPER.get(from) : from;
return notPrimitiveTo.isAssignableFrom(notPrimitiveFrom);