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 ...
随机推荐
- 软件开发工具——Make
掌握Makefile的使用方法和工作流程: 掌握make工具变量的相关知识,包括其引用.定义及分类等: 掌握Makefile常见的函数含义: 掌握Makefile与shell命令行的通信方法: 掌握M ...
- Sword框架解析——知识采集流程页面初始化
Sword框架解析——知识采集流程页面初始化 Sword框架解析知识采集流程页面初始化 问题解答流程采集新增页面初始化 1后台t_xt_gnzy表和BLH类 2BLH类的写法前台目录树代码 3登录系统 ...
- Vue中使用节流Lodash throttle
在Vue中,有时需要对ajax请求提交进行节流操作.这时候,如果页面在请求成功之后会跳转,使用vue指令once或者加载一个loading遮罩禁止点击即可,但如果请求之后不跳转,并且loading不适 ...
- webpack CommonsChunkPlugin 提取公共代码
1.项目结构 2.部分代码 module.js console.log('module.js'); index文件夹下的index.js require('../module.js'); consol ...
- linux cut 命令
cut:以某种方式按照文件的行进行分割 参数列表: -b 按字节选取 忽略多字节字符边界,除非也指定了 -n 标志 -c 按字符选取 -d 自定义分隔符,默认为制表符. -f 与-d一起使用,指定显示 ...
- Mybatis 通过扫描 自动生成别名
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" ...
- Shell36计
常用命令: date:查看日期 [root@centos-01 conf]# date 2018年 07月 12日 星期四 15:17:39 CST [root@centos-01 conf]# [r ...
- REST开放接口生成文档工具之apidoc
一.安装node.js环境 感谢阿里云,下载的链接http://npm.taobao.org/mirrors/node/latest-v6.x/ 二.安装apidoc npm install apid ...
- python 火车票爬取代码
1.根据搜索词下载百度图片: # -*- coding: utf-8 -*- """根据搜索词下载百度图片""" import re imp ...
- mysql 主主复制(双主复制)报错Last_SQL_Errno: 1146
Last_Errno: 1146 Last_Error: Error 'Table 'test.user' doesn't exist' on query. Default database: 'te ...