Class中isAssignableFrom() 方法
看Spring源码的时候看到这个方法:
protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
Class<?> contextClass = determineContextClass(sc);
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
"] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
}
return (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
}
第一次见到第三行中的用法,点开看了下,原文是这么说的:
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.
就是说判断一个类是否另一个类或接口的子类。
例如
A.class.isAssignableFrom(B.class)
这句就是判断 B是否A的父接口或者父类。
顺手搜了下,得到一个小惊喜:
instanceof, isinstance,isAssignableFrom的区别
Class中isAssignableFrom() 方法的更多相关文章
- Java中isAssignableFrom()方法与instanceof()方法用法
一句话总结: isAssignableFrom()方法是从类继承的角度去判断,instanceof()方法是从实例继承的角度去判断. isAssignableFrom()方法是判断是否为某个类的父类, ...
- Class的isAssignableFrom方法
Class类的isAssignableFrom是个不常用的方法,感觉这个方法的名字取得不是很好,所以有必要在此解析一下,以免在看源码时产生歧义,这个方法的签名如下: public native boo ...
- category中重写方法?
问:可以在category中重写方法吗? 答:代码上可以实现 在category中重写方法,但在实际开发中,不建议这样做.如果确实需要重写原有方法也建议使用子类进行重写. category是为了更方便 ...
- JQuery中$.ajax()方法参数详解 及 async属性说明
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- jQuery中eq()方法用法实例
本文实例讲述了jQuery中eq()方法用法.分享给大家供大家参考.具体分析如下: 此方法能够获取匹配元素集上的相应位置索引的元素. 匹配元素集上元素的位置索引是从0开始的. 语法结构: 复制代码 代 ...
- Java中,方法的重写、重载的区别,以及多态的实例
首先我们要明白什么是重写和重载 重写(override):子类方法覆盖了父类的方法. (类与类之间继承的关系) 例:父类代码 public class Deng { public void Qi ...
- 深度理解Jquery 中 offset() 方法
参考原文:深度理解Jquery 中 offset() 方法
- 第6章 Java类中的方法
1.如何定义java的方法 什么是方法:方法使用来解决一类问题的代码集合,是一个功能模块在类中定义个方法的方法是: 访问修饰符 返回值类型 方法名(参数列表){ 方法体 } 1.访问修饰符,是限制该方 ...
- 第三章Struts2 Action中动态方法调用、通配符的使用
01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...
随机推荐
- 流编辑器sed
sed与grep一样,都起源于老式的ed编辑器,因其是一个流编辑器(stream editor)而得名.与vi等编辑器不同,sed是一种非交互式编辑器(即用户不必参与编辑过程),它使用预先设定好的编辑 ...
- POI按行读取word,并去掉属性标签内容:超链接
public String readDoc(File file) { StringBuffer buffer = new StringBuffer(); InputStream input = nul ...
- windows合并文件夹窗口
windows合并文件夹窗口 CreateTime--2017年7月26日16:28:14Author:Marydon 右击任务栏-->属性-->任务栏按钮选项-->选择“始终合 ...
- 总结一些js自定义的函数
1.dayin() 作用:将id为dayin的内容,新建页面并打印,可解决打印某页面中的部分内容的问题. 使用方法:将要打印的内容通过 <span id="dayin"> ...
- [SDOI2016Round1]解题报告
Day1 T1: 题意:求∑n−1i=0∑m−1j=0max((i xor j)−k,0) 由于是抑或操作.每一位都是独立的,所以能够一位一位的算贡献. f[i][a][b][c]表示第i位时.每一个 ...
- JNI调用之本地库文件的安装
在进行JNI调用的时候.是由java的本地接口调用本地库文件来完毕的,可是本地库文件须要放置到指定位置.JNI接口才干调用到,这个路径是由JVM的系统变量"java.library.path ...
- mark v1 SecurityConfig
package cn.efunbox.cms.configuration; import cn.efunbox.afw.core.entity.ApiCode; import cn.efunbox.a ...
- ecshop报错”Deprecated: Assigning the return value of…”解决办法
ECSHOP生成站点地图提示”Deprecated: Assigning the return value of new by reference is deprecated in…”. 我的问题在批 ...
- 用注册表更改DNS的代码分享
用注册表更改DNS,1秒切换完毕,快速又方便,不用麻烦的去等待了,支持远程路劲运行 最进我这里DNS老是间歇性掉,很不稳定,广州地区,如果你的DNS经常需要更换,试试这个批处理, 论坛很多人发过了更改 ...
- 对象.delegate=self的理解
整理自:http://www.cocoachina.com/ask/questions/show/87430 各位大神,对象.delegate=self是啥意思,委托的意思不就是自己的任务交给其他人去 ...