java isassignablefrom 判断子父类关系
2014-03-17 11:27
344 查看
java.lang.Class
详细见API.
java 文档说明。
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface
of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false. If this Class object represents a primitive type, this method returns true if the specified Class parameter is exactly this Class object;
otherwise it returns false.
Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented
by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
代码使用
可以用来校验一个类是否实现指定的父类。
详细见API.
/** * Determines if the class or interface represented by this * {@code Class} object is either the same as, or is a superclass or * superinterface of, the class or interface represented by the specified * {@code Class} parameter. It returns {@code true} if so; * otherwise it returns {@code false}. If this {@code Class} * object represents a primitive type, this method returns * {@code true} if the specified {@code Class} parameter is * exactly this {@code Class} object; otherwise it returns * {@code false}. * * <p> Specifically, this method tests whether the type represented by the * specified {@code Class} parameter can be converted to the type * represented by this {@code Class} object via an identity conversion * or via a widening reference conversion. See <em>The Java Language * Specification</em>, sections 5.1.1 and 5.1.4 , for details. * * @param cls the {@code Class} object to be checked * @return the {@code boolean} value indicating whether objects of the * type {@code cls} can be assigned to objects of this class * @exception NullPointerException if the specified Class parameter is * null. * @since JDK1.1 */ public native boolean isAssignableFrom(Class<?> cls);
java 文档说明。
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface
of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false. If this Class object represents a primitive type, this method returns true if the specified Class parameter is exactly this Class object;
otherwise it returns false.
Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented
by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
代码使用
public class AssingableTest { public static void main(String[] args) { Class<?> parent = java.io.InputStream.class; Class<?> child = java.io.FileInputStream.class; System.out.println(parent.isAssignableFrom(child)); } }
可以用来校验一个类是否实现指定的父类。
相关文章推荐
- Java中final关键字用法总结
- 深入探讨 java.lang.ref 包
- ibatis java.util.Map作为parameterClass和resultClass(转)
- Java多线程(三)、线程同步
- java的覆盖和隐藏的区别
- Java多线程(一)、多线程的基本概念和使用
- java 静态方法不能被override
- Myeclipse/Eclipse中修改WebContent/WebRoot
- java类初始化顺序
- JAVA_银行业务调度系统
- spring aop 实现读写分离
- javaweb之jstl+el完成数据迭代
- Java进阶篇--容器(二)
- JAVA_交通灯管理系统
- java 中 class类作用
- JAVA虚拟机体系结构
- StringUtils
- Spring整合jaxws基于handles验证
- 使用myeclipse时出现java.lang.UnsupportedClassVersionError: Bad version number in .class file
- java字符串截取