什么是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 ...
随机推荐
- Apache DolphinScheduler 荣获国外知名媒体采访
Apache DolphinScheduler 毕业的消息被北美科技媒体 TheNewStack 关注并邀请Apache DolphinScheduler PMC chair 代立冬 进行相关采访. ...
- LuoguP3128 [USACO15DEC]最大流Max Flow (树上差分)
跟LOJ10131暗的连锁 相似,只是对于\(lca\)节点把它和父亲减一 #include <cstdio> #include <iostream> #include < ...
- bbs项目解读
1.注册功能 具体的效果图如下: 注册功能涉及到的逻辑步骤: 1.搭建前端html页面 2.向后端提交用户输入数据 3.对用户输入的数据格式进行校验 4.页面输入数据格式错误,及时向用户进行提示/正确 ...
- linux之间上传下载--SCP
1.远程拷贝文件 [root@rhel8-client01 yum.repos.d]# scp root@192.168.72.149:/etc/yum.repos.d/* . (.表示拷贝到当前文件 ...
- [CF1539F] Strange Array (线段树)
题面 有一个长度为 n \tt n n 的序列 a \tt a a ,对于每一个位置 i ∈ [ 1 , n ] \tt i\in[1,n] i∈[1,n]: 选择一个区间 [ l , r ] \tt ...
- java基础———标识符和关键字
标识符以字母开头 (A-Z)或(a-z) 美元符($) 下划线(_) 不能以关键字作为变量名或者方法名 标识符大小写不能混淆 可以中文(不建议) 常用的关键字
- SpringBoot集成Thymeleaf发送Html邮件报错
由于业务需求需要使用Thymeleaf作为模板发送Html邮件,开发调试过程中发生以下错误 org.thymeleaf.exceptions.TemplateInputException: Error ...
- React的生命周期函数
概述 在React中,生命周期函数指的是组件在某一个时刻会自动执行的函数 constructor 在类或组件创建的时候被自动执行,我们可以说它是生命周期函数,但它并不是React所特有的,所有的Es6 ...
- SpringMVC 02: SpringMVC响应get和post请求 + 5种获取前端数据的方式
响应get和post请求 SpringMVC中使用@RequestMapping注解完成对get请求和post请求的响应 项目结构和配置文件与SpringMVC博客集中的"SpringMVC ...
- 如何守护数据安全? 这里有一份RDS灾备方案为你支招
当今世界是一个充满着数据的互联网世界,生活的方方面面都在不断产生着数据,比如出行记录.消费记录.浏览的网页.发送的消息等等.除了文本类型的数据,图像.音乐.声音都是数据.对于企业而言,数据更是重要的生 ...