java isassignablefrom 判断子父类关系
来源:互联网 发布:2016中国汽车销量数据 编辑:程序博客网 时间:2024/06/06 01:36
java.lang.Class
详细见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 isassignablefrom 判断子父类关系
- JAVA isAssignableFrom 判断父子关系
- java 判断类和实例的关系(instanceof,isInstance,isAssignableFrom)
- JAVA判断对象是不是属于哪一个类 instanceof , isInstance ,isAssignableFrom
- Java isAssignableFrom 理解
- java instanceof与isAssignableFrom
- Java-----instanceof、isInstance、isAssignableFrom
- Java isAssignableFrom、instanceof 、isInstance
- java isAssignableFrom 用法
- isAssignableFrom
- Java中isAssignableFrom和instanceof
- Java中isAssignableFrom的用法
- Java继承关系的判断
- 【Java知识点】Java中isAssignableFrom、instanceof、isInstance
- 关于 java.lang.Class.isAssignableFrom() 方法
- Java中的instanceof,isInstance和isAssignableFrom
- 【Java基础】Class.isAssignableFrom与 instanceof 区别
- 【集腋成裘】类型判断(instanceof、isInstance、isAssignableFrom、equals)
- 通过实验窥探javascript的解析执行顺序
- 类该如何抽取和定义
- 深入探讨 java.lang.ref 包
- javascript的一些特性
- PHP FTP操作类( 上传、拷贝、移动、删除文件/创建目录 )
- java isassignablefrom 判断子父类关系
- Python 使用 Xlrd/xlwt 操作 Excel
- LeetCode Minimum Depth of Binary Tree
- Android的三种网络通信方式
- 第二周作业01 -- 素数的算法实现
- Python 学习经历(一) :python语法总结
- Codeforces Round #194 (Div. 2)
- Chrome OS (hexxeh编译版本)安装到硬盘的方法修正
- SmartMio:懒人健身专用,八块腹肌等着你