工具类:判断一个类是否是给定类的子类

来源:互联网 发布:商业源码网 编辑:程序博客网 时间:2024/06/11 15:21
public class ClassUtils {    /**     * Checks if a class is a subclass of a class with the specified name. Used     * as an instanceOf without having to load the class, useful when trying to     * check for classes that might not be available in the runtime JRE.     *      * @param clazz     *            The class to check     * @param className     *            The class name to look for in the super classes     * @return true if the class extends a class by the specified name.     */    public static boolean extendsClass(final Class<?> clazz, String className) {        Class<?> superClass = clazz.getSuperclass();        while (superClass != null) {            if (superClass.getName().equals(className)) {                return true;            }            superClass = superClass.getSuperclass();        }        return false;    }}


	
				
		
原创粉丝点击