Class中isAssignableFrom() 方法

看Spring源码的时候看到这个方法:

1     protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
2         Class<?> contextClass = determineContextClass(sc);
3         if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
4             throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
5                     "] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
6         }
7         return (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
8     }

 

第一次见到第三行中的用法,点开看了下,原文是这么说的:

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的区别

 

参考资源链接:[Ubuntu命令行实用指南](https://wenku.youkuaiyun.com/doc/2kjvz7rha0?utm_source=wenku_answer2doc_content) 在Ubuntu系统中,软件包管理是一个重要的任务,而`apt-get autoremove`命令就是用来移除那些已经不再需要的孤立软件包的。孤立软件包是指那些原本需要依赖的软件包已经被删除,而它们本身已经没有作用的软件包。为了确保系统清理彻底,你还需要执行`apt-get autoclean`来清除已经下载的不再需要的旧版本软件包,以及执行`sudo apt-get clean`来清理所有软件包缓存。这三步操作可以确保系统中不必要的软件包和缓存被完全清理。具体操作如下: 1. 打开终端。 2. 输入命令 `sudo apt-get autoremove` 并执行。系统会列出所有即将被移除的孤立软件包,并请求你的确认。 3. 输入`Y`并回车确认,开始清理孤立软件包。 4. 接下来,输入命令 `sudo apt-get autoclean` 清除旧版本软件包,这个命令只清理那些下载过的、现在已经安装不了的软件包。 5. 最后,输入命令 `sudo apt-get clean` 清除所有软件包缓存,包括下载的软件包和索引列表。 执行上述命令后,你的Ubuntu系统将会更加清洁,运行效率也会有所提升。建议定期运行这些命令,保持系统的整洁。如果想要深入了解这些命令及其背后的原理和更多用法,可以查阅《Ubuntu命令行实用指南》。这份指南不仅提供了命令的详细解释和使用示例,还包括了其他许多在Ubuntu命令行中常用的命令和技巧,是系统管理员和高级用户的宝贵资源。 参考资源链接:[Ubuntu命令行实用指南](https://wenku.youkuaiyun.com/doc/2kjvz7rha0?utm_source=wenku_answer2doc_content)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值