看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() 方法的更多相关文章

  1. Java中isAssignableFrom()方法与instanceof()方法用法

    一句话总结: isAssignableFrom()方法是从类继承的角度去判断,instanceof()方法是从实例继承的角度去判断. isAssignableFrom()方法是判断是否为某个类的父类, ...

  2. Class的isAssignableFrom方法

    Class类的isAssignableFrom是个不常用的方法,感觉这个方法的名字取得不是很好,所以有必要在此解析一下,以免在看源码时产生歧义,这个方法的签名如下: public native boo ...

  3. category中重写方法?

    问:可以在category中重写方法吗? 答:代码上可以实现 在category中重写方法,但在实际开发中,不建议这样做.如果确实需要重写原有方法也建议使用子类进行重写. category是为了更方便 ...

  4. JQuery中$.ajax()方法参数详解 及 async属性说明

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  5. jQuery中eq()方法用法实例

    本文实例讲述了jQuery中eq()方法用法.分享给大家供大家参考.具体分析如下: 此方法能够获取匹配元素集上的相应位置索引的元素. 匹配元素集上元素的位置索引是从0开始的. 语法结构: 复制代码 代 ...

  6. Java中,方法的重写、重载的区别,以及多态的实例

    首先我们要明白什么是重写和重载 重写(override):子类方法覆盖了父类的方法.    (类与类之间继承的关系) 例:父类代码 public class Deng { public void Qi ...

  7. 深度理解Jquery 中 offset() 方法

    参考原文:深度理解Jquery 中 offset() 方法

  8. 第6章 Java类中的方法

    1.如何定义java的方法 什么是方法:方法使用来解决一类问题的代码集合,是一个功能模块在类中定义个方法的方法是: 访问修饰符 返回值类型 方法名(参数列表){ 方法体 } 1.访问修饰符,是限制该方 ...

  9. 第三章Struts2 Action中动态方法调用、通配符的使用

    01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...

随机推荐

  1. Oracle DB 数据库维护

    • 管理优化程序统计信息 • 管理自动工作量资料档案库(AWR) • 使用自动数据库诊断监视器(ADDM) • 说明和使用指导框架 • 设置预警阈值 • 使用服务器生成的预警 • 使用自动任务   数 ...

  2. SLAX初体验

    Slax是一个便捷.便携的Linux操作系统.它的界面既充满时尚感,又可基于不同模块的功能运作.它的界面富有时尚感,并集成了不同的模块的界面.尽 管它的容量十分娇小,Slax依然预载了不少日常应用的软 ...

  3. 算法笔记_034:大整数乘法(Java)

    目录 1 问题描述 2 解决方案 2.1 蛮力法   1 问题描述 计算两个大整数相乘的结果. 2 解决方案 2.1 蛮力法 package com.liuzhen.chapter5; import ...

  4. Laravel 隐藏域如何实现?

    Laravel 隐藏域如何实现?   在 Blade 模板中,我们可以使用 method_field 方法来创建隐藏域.   {{ method_field('DELETE') }} 其转化为 HTM ...

  5. TP框架模板中IF Else 如何使用?

    TP框架模板中IF Else 如何使用? 截个图吧 如果效果出不来,一般就是条件写错了!!!

  6. CommonClassLoader或SharedClassLoader加载的Spring如何访问并不在其加载范围内的用户程序呢

    Question 引自<深入理解Java虚拟机—JVM高级特性与最佳实践>9.2.1,p235 如果有10个WEB应用程序都是用spring来进行组织管理的话,可以把Spring放到Com ...

  7. wait & waitpid 以及子进程传给父进程的信号分析

    wait() 和 waitpid() wait() 系统调用挂起调用进程的执行直到有一个孩子终止.调用 wait(&status) 等价于: waitpid(-1, &status, ...

  8. unix 网络编程第八章 UDP

    code 见 https://github.com/juniperdiego/Unix-network-programming-of-mine/tree/master/udpserv01 1 建立so ...

  9. oracle 查看锁表情况与解表

      oracle 查看锁表情况与解表 CreateTime--2018年4月27日17:24:37 Author:Marydon 1.锁表查询 --锁表查询 SELECT OBJECT_NAME AS ...

  10. Android studio中导入第三方类库

    常常在github上看到一些好用的框架,但是对于一个新手怎样在android studio上导入去总会遇到各种麻烦,索性来研究下第三方类库怎样在android studio上导入. 以我在github ...