Java Utililty Methods Class Type Check

List of utility methods to do Class Type Check

Description

The list of methods to do Class Type Check are organized into topic(s).

Method

booleanisAssignable(final Class target, final Class source)
Checks if target class is assignable from source class in terms of auto(un)boxing.
if (target == null || source == null) {
    throw new IllegalArgumentException("classes");
if (target.isArray() && source.isArray()) {
    return isAssignable(target.getComponentType(), source.getComponentType());
return tryFromPrimitive(target).isAssignableFrom(tryFromPrimitive(source));
booleanisAssignableFrom(Class clazzA, Class clazzB)
is Assignable From
if (!(clazzA.isPrimitive() ^ clazzB.isPrimitive())) {
    return clazzA.isAssignableFrom(clazzB);
} else if (clazzA.isPrimitive()) {
    final Class oClazzA = (Class) convertor.get(clazzA);
    return oClazzA.isAssignableFrom(clazzB);
} else {
    final Class oClazzB = (Class) convertor.get(clazzB);
    return clazzA.isAssignableFrom(oClazzB);
...
booleanisBasicType(Class clazz)
is Basic Type
return !Collection.class.isAssignableFrom(clazz)
        && (clazz.equals(Integer.class) || clazz.equals(Integer.TYPE) || clazz.equals(Long.class)
                || clazz.equals(Long.TYPE) || clazz.equals(Boolean.class) || clazz.equals(Boolean.TYPE)
                || clazz.equals(Float.class) || clazz.equals(Float.TYPE) || clazz.equals(Double.class)
                || clazz.equals(Double.TYPE) || clazz.equals(Byte.class) || clazz.equals(Byte.TYPE)
                || clazz.equals(String.class) || Date.class.isAssignableFrom(clazz));
booleanisClassBelowPackage(Class theClass, List packageList)
Returns whether the specified class is either within one of the specified packages or within a subpackage of one of the packages
String classPackage = theClass.getPackage().getName();
for (Object packageName : packageList) {
    if (packageName != null) {
        if (classPackage.startsWith(packageName.toString())) {
            return true;
return false;
booleanisCollection(Class clazz)
is Collection
return isMap(clazz) || Collection.class.isAssignableFrom(clazz);
booleanisCollection(Class cls)
is Collection
return Collection.class.isAssignableFrom(cls);
booleanisCollectionMapOrArray(Class type)
is Collection Map Or Array
if (type.isArray())
    return true;
if (Collection.class.isAssignableFrom(type))
    return true;
if (Map.class.isAssignableFrom(type))
    return true;
return false;
booleanisComposite(Class cls)
is Composite
return isArray(cls) || isCollection(cls);
booleanisEmptyCollectionOrMap(Object content, Class type)
is Empty Collection Or Map
if (Collection.class.isAssignableFrom(type)) {
    if (content == null) {
        return true;
    } else {
        if (((List) content).isEmpty()) {
            return true;
} else if (Map.class.isAssignableFrom(type)) {
    if (content == null) {
        return true;
    } else {
        if (((List) content).isEmpty()) {
            return true;
return false;
booleanisInPrimitiveWrapperType(Class type)
Return whether the Primitive Wrapper Type Map contain the given type.
return primitiveWrapperTypeMap.containsValue(type);