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; } }
工具类:判断一个类是否是给定类的子类
最新推荐文章于 2022-07-27 11:21:53 发布