Java Class InstanceOf instanceOf(Class clazz, Class target)

Here you can find the source of instanceOf(Class clazz, Class target)

Description

instance Of

License

Open Source License

Declaration

public static boolean instanceOf(Class clazz, Class target) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static boolean instanceOf(Class clazz, Class target) {
        if (clazz == null)
            return false;
        if (clazz == target)
            return true;
        if (target.isInterface()) {
            for (Class aClass : clazz.getInterfaces()) {
                if (aClass == target)
                    return true;
            }//from   w  w w  . j a  v  a 2 s  .  c  o  m
        }
        if (clazz.getSuperclass() == target)
            return true;
        else {
            if (clazz.isInterface()) {
                for (Class aClass : clazz.getInterfaces()) {
                    if (instanceOf(aClass, target))
                        return true;
                }
            }
            return instanceOf(clazz.getSuperclass(), target);
        }
    }
}

Related

  1. instanceOf(Class clazz, Class superClass)
  2. instanceOf(Class left, Class right)
  3. instanceOf(Class tester, Class instance)
  4. instanceOf(Class beanClass, Object element)
  5. instanceOf(Class objectClass, Class typeClass)