什么是subsignature和return-type-substitutable
subsignature
什么是签名(signature)
方法签名组成:方法名+参数列表(参数的类型、个数、顺序)
Java语言层面规定的签名是不包含返回值类型的;
JVM层面规定的签名是包含返回值类型的。
常见于:重写和重载
什么是子签名(subsignature)
假定有两个方法m和n,m和n具有相同的方法名,相同的参数列表,并且n的形参类型在调整(类型擦除)之后和m的形参类型相同。此时我们就可以说:
方法m的签名是方法n的签名的子签名。
举个例子:
interface M {
void m(List list);
}
interface N {
void m(List<String> list);
}
interface Demo extends M,N{
//正因为M.m是子签名,所以Demo也是一个函数式接口
//M.m可以覆盖N.m,所以Demo这里选择的是M.m
}
上面代码中的M.m的签名就是N.m签名的子签名,因为N.m的签名经过类型擦除之后就是M.m的签名。
子签名的概念旨在表示两种方法之间的关系,这些方法的签名不完全相同,但是其中一个可以覆盖另一个方法。具体来说,它允许签名不使用泛型类型的方法覆盖该方法的任何泛化版本。
return-type-substitutable
return-type-substitutable 翻译到中文的意思就是:返回类型可替换。
借用上面的例子:
interface M {
List<String> m(List list);
}
interface N {
List m(List<String> list);
}
interface Demo extends M,N{
}
其中,M.m的返回值是List<String>,N.m的返回值List,两者可以兼容,即它们的返回类型可替换。
什么意思呢?看看下面这个代码也许你就会明白。
//这个例子只是为了更好理解
List m(List list){
return n(list);
}
List<String> n(List<String> list){
return m(list);
}
也就是说M.m的返回值可以接受N.m的返回值,反过来也是。
详细了解可以看下官方Java语言规范§8.4.5
知乎关于Java8 Functional Interface 疑问的解答

什么是subsignature和return-type-substitutable的更多相关文章
- 使用JFinal的第一个项目出现的问题(The return type is incompatible with JspSourceDependent.getDependants())
四月 08, 2016 4:35:34 下午 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() fo ...
- Generic method return type
Here's the Animal class: public class Animal{ private Map<String,Animal> friends =new HashMap& ...
- c++11: trailing return type in functions(函数返回类型后置)
In C++03, the return type of a function template cannot be generalized if the return type relies on ...
- solr6.3 + Hbase Indexer使用MR创建索引,错误Bad return type
使用solr6.3 + Hbase Indexer ,通过Hbase-indexer从Hbase建立索引到solr中,进行全文搜索. 两种实现方式:① 开启hbase-indexer进行实时同步新数据 ...
- 解决C语言程序报错:return type defaults to‘int’
下面是通过自定义一个函数printN,之后在main函数中调用printN,使得可以通过输入整数N,将从1到N的全部整数都打印出来的程序. 但是在编译过程中却报错: return type defau ...
- delete attempted to return null from a method with a primitive return type (int)
今天被自己给蠢死了 今天在代码中遇到这个错误, 百度翻译一下:映射方法,从一org.system.mapper.child.chmorganizationexaminationmapper.delet ...
- rg.apache.ibatis.binding.BindingException: Mapper method 'com.dao.Cameao.getOnlineDayRation attempted to return null from a method with a primitive return type (float)
本文为博主原创,未经允许不得转载: 异常展示如下: org.apache.ibatis.binding.BindingException: Mapper method 'com.dao.Cameao. ...
- 【c++错误】类的语法错误 error c2533:constructors not allowed a return type(构造函数不允许返回一个类型)
今天编写类的程序的时候不小心把类后的分号忘写了,就出现上面的错误提示. 顺便复习下类的正确格式: class 类名 { public: //习惯上将公有类型放在前面,便于阅读 ……(外部接口) pro ...
- Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!
Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as ...
- mysql查询null异常:attempted to return null from a method with a primitive return type
select sum(deposit_amount)from tb_commission_ib_day mysql查询时报异常: attempted to return null from a met ...
随机推荐
- 宜宾市黑烟车电子抓拍系统App
2020.11 - 2021.06负责手机App开发 项目说明: 主要用于管理人员的移动办公,通过与管理平台共享数据库,实现:人工审核.推送交警.账户管理.信息查询.数据统计.点位电子地图.设备 ...
- ES6 Promise详解
前言 本文主要是对Promise本身的用法做一个全面解析而非它的原理实现,如果你对Promise的用法还不是很熟悉或者想加深你对Promise的理解,我相信这篇文章一定会帮到你. 首先让我们先了解一下 ...
- 盘点Vue2和Vue3的10种组件通信方式(值得收藏)
Vue中组件通信方式有很多,其中Vue2和Vue3实现起来也会有很多差异:本文将通过选项式API 组合式API以及setup三种不同实现方式全面介绍Vue2和Vue3的组件通信方式.其中将要实现的通信 ...
- Mybatis的ResultMap与limit分页查询
ResultMap主要解决的是:属性名和字段不一致 如果在pojo中设置的是一个名字,在数据库上又是另一个名字,那么查询出来的结果或者其他操作的结果就为null. //在pojo中 private S ...
- Python入门系列(六)一篇学会python函数
函数 函数是只在调用时运行的代码块. def my_function(): print("Hello from a function") my_function() 信息可以作为参 ...
- 第七十八篇:写一个按需展示的文本框和按钮(使用ref)
好家伙, 我们又又又来了一个客户 用户说: 我想我的页面上有一个搜索框, 当我不需要他的时候,它就是一个按钮 当我想要搜索的时候,我就点一下它, 然后按钮消失,搜索框出现, 当我在浏览其他东西时,这个 ...
- 本地 maven + scala 跑spark wordcount
pom.xml 点击查看代码 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http: ...
- mysql explain总结
Explain 包含字段 id select_type table type possible_keys key key_len ref rows extra 字段解释 1. id id 相同则执行顺 ...
- haodoop新特性
Hadoop2.x新特性 scp实现两个远程主机之间的文件复制 scp -r hello.txt root@hadoop103:/user/atguigu/hello.txt // 推 push sc ...
- 【微服务】- Nacos - 注册中心
微服务 - 注册中心 - Nacos 生命不息,写作不止 继续踏上学习之路,学之分享笔记 总有一天我也能像各位大佬一样 一个有梦有戏的人 @怒放吧德德 分享学习心得,欢迎指正,大家一起学习成长! 上一 ...