Java Utililty Methods Class InstanceOf

List of utility methods to do Class InstanceOf

Description

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

Method

booleaninstanceOf(Class clazz, Class superClass)
instance Of
return clazz != null && superClass != null && clazz.isAssignableFrom(superClass);
booleaninstanceOf(Class clazz, Class target)
instance Of
if (clazz == null)
    return false;
if (clazz == target)
    return true;
if (target.isInterface()) {
    for (Class aClass : clazz.getInterfaces()) {
        if (aClass == target)
            return true;
...
booleaninstanceOf(Class left, Class right)
Check if left type is same type or subtype of right type using same conventions as java instanceof expression but apply to type.
return left.isAssignableFrom(right);
booleaninstanceOf(Class tester, Class instance)
instance Of
try {
    tester.asSubclass(instance);
    return true;
} catch (Exception ignored) {
return false;
booleaninstanceOf(Class beanClass, Object element)
instance Of
return element != null && beanClass.isAssignableFrom(element.getClass());
booleaninstanceOf(Class objectClass, Class typeClass)
Tests if a class is the same class as, or sub-class of, or implements typeClass.
if (objectClass == typeClass) {
    return true;
if (objectClass.isInterface()) {
    if (typeClass.isInterface()) {
        Class<?>[] ifaces = objectClass.getInterfaces();
        for (Class<?> iface : ifaces) {
            if (iface == typeClass) {
...
booleaninstanceOf(Class parant, Class chield)
instance Of
if (parant == null)
    throw new NullPointerException("parant is null");
if (chield == null)
    throw new NullPointerException("chield is null");
if (parant.equals(chield))
    return true;
return parant.isAssignableFrom(chield);
booleaninstanceOf(Class test, Class clazz)
Checks if a class is instance of an other class.
if (test.equals(clazz))
    return true;
for (Class<?> i : test.getInterfaces()) {
    if (i.equals(clazz))
        return true;
return false;
booleaninstanceOf(final Class classVerifiable, final Class classAssignable)
The instanceof command is used to determine if a Java class is of a given type.
return classAssignable.isAssignableFrom(classVerifiable);
booleaninstanceOf(final Object a, final Class b)
instance Of
return b.isInstance(a);