is Object Instance Of a Class - Android java.lang.reflect

Android examples for java.lang.reflect:Object Type

Description

is Object Instance Of a Class

Demo Code


//package com.java2s;

public class Main {
    public static boolean isInstanceOf(Object obj, Class<?> clazz) {
        if (obj == null || clazz == null) {
            return false;
        }/*from   w  w w.  j a  v a  2 s. c  om*/
        Class<?> objClass = obj.getClass();

        while (objClass != null) {
            if (clazz.equals(objClass)) {
                return true;
            }
            objClass = objClass.getSuperclass();
        }

        return false;
    }
}

Related Tutorials