什么是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 ...
随机推荐
- ENSP NE40E 报错(NE1启动操作超时,请检查与服务器链接后重试!)
前言:某网友淘宝找我咨询NE40E启动失败的问题,事后我整理的处理过程,供各位同行参考. 系统版本:windows 10 软件版本: ENSP:V100R003C00 virtual BOX:5.2. ...
- PerfView专题 (第八篇):洞察 C# 内存泄漏之寻找静态变量名和GC模式
一:背景 这篇我们来聊一下 PerfView 在协助 WinDbg 分析 Dump 过程中的两个超实用技巧,可能会帮助我们快速定位最后的问题,主要有如下两块: 洞察内存泄漏中的静态大集合变量名. 验证 ...
- c# 异步进阶————channel [一]
前言 该系列为异步编程的进阶篇,其实也不能这么讲.世界上本没有进阶篇,只能说是高级篇(高级篇不能说多高级,是对底层的封装的意思),只要是加深理解都是进阶. 本章先介绍一下channel. 正文 下面没 ...
- openstack中Neutron组件简解
一.Neutron概述 Neutron 的设计目标是实现"网络即服务(Networking as a Service)".为了达到这一目标,在设计上遵循了基于 SDN 实现网络虚拟 ...
- KingbaseES R3集群备库执行sys_backup.sh物理备份案例
案例说明: KingbaseES R3的后期版本支持通过sys_backup.sh执行sys_rman的物理备份,实际上是调用了sys_rman_v6的工具做物理备份.本案例是在备库上执行集群的备份, ...
- 电商平台物流模块自建OR对接第三方物流平台
前沿 近几年来,电商行业竞争变得愈加激烈,公域流量获客成本越来越高,电商平台规则也越来越严格,数据无法出塔,商家无法自主运营用户群等等原因,很多大品牌纷纷开始搭建自有商城,运营私域流量,以此来降低 ...
- Dockerfile文件:设置变量启动的时候传递进去
from openjdk:8-jdk-alpine RUN ln -sf /usr/share/zoneinfo/Asia/shanghai /etc/localtime RUN echo 'Asia ...
- Linux yum安装PostgreSQL9.6
PostgreSQL10版本的主从安装配置在 https://www.cnblogs.com/virtulreal/p/11675841.html 一.下载安装 1.创建PostgreSQL9.6的y ...
- Logstash:解析 JSON 文件并导入到 Elasticsearch 中
转载自:https://elasticstack.blog.csdn.net/article/details/114383426 在今天的文章中,我们将详述如何使用 Logstash 来解析 JSON ...
- Jenkins 中使用 Git Parameter 插件动态获取 Git 的分支