工具类:判断一个类是否是给定类的子类
2012-03-20 10:43
281 查看
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;}}
相关文章推荐
- 题目1.请给出一个运行时间为O(nlgn)的算法,使之能在给定一个由n个整数构成的集合S和另一个证书x时,判断出S中是否存在有两个其和等于x的元素。
- 在 Java 的多线程中,如何去判断给定的一个类是否是线程安全的(另外:synchronized 同步是否就一定能保证该类是线程安全的。)
- 判断一个有序数组中是否有两个数的和等于给定的数
- StringUtils 工具类中判断一个string类型的值是否为空的几种方法
- 原有一组数据区间段,给定一个区间,判断此区间是否和其他区间相交
- 面试题精选(76):给定BST先序遍历序列,不构造BST的情况下判断BST是否每个node都只有一个child
- java:给定一个整型数,判断是否是2的幂次
- Swift:如何判断一个对象是否是某个类(或其子类)的实例
- 【华为面试题】给定一个数字(整数),判断它是否回文
- 每天一道算法题(一):给定一个整数,判断这个数是否是回文
- 编写正则表达式,判断给定的是否是一个合法的IP地址。
- 给定一个入栈顺序和一个出栈顺序,判断出栈顺序是否可能
- 判断一个给定的路径是否是目录 isDirectory()
- 1.实现一个函数,可以左旋字符串中的k个字符。 AABCD左旋一个字符得到ABCDA AABCD左旋两个字符得到BCDAA 2.判断一个字符串是否为另外一个字符串旋转之后的字符串。 例如:给定s1
- 判断一个运用是否在运行的工具类
- 在java中怎么理解“用instanceof操作符判断父类对象是否为子类的一个实例”?
- 给定一个链表,判断是否是回文
- leetcode动态规划之判断一个字符串是否是给定字符串数组组合出来的
- 编写正则表达式,判断给定的是否是一个合法的IP地址。