is Child Class - Java Reflection

Java examples for Reflection:Class

Description

is Child Class

Demo Code


//package com.java2s;

import java.util.HashMap;

public class Main {
    private static HashMap<Class<?>, Class<?>> primativeClassMap = new HashMap<Class<?>, Class<?>>();

    private static boolean isChildClass(Class<?> origClass,
            Class<?> dstClass) {
        if (dstClass == null)
            return true;
        if (origClass.isInterface()) {
            for (Class<?> i : dstClass.getInterfaces()) {
                if (origClass == i)
                    return true;
            }//  w  w w . jav  a 2  s.c o  m
        }
        if (origClass.isPrimitive()
                && (primativeClassMap.get(origClass) == dstClass))
            return true;
        for (; dstClass != Object.class; dstClass = dstClass
                .getSuperclass()) {
            if (dstClass == origClass)
                return true;
        }
        return false;
    }
}

Related Tutorials