java - 使用泛型类型时如何打印编译器推断的有界类型?
问题描述
考虑以下代码段:
List<Exception> exceptionList = Arrays.asList(new Exception("344"));
List<Error> errorList = Arrays.asList(new Error("44"));
//consider a hypothetical function that can print the generic string corresponding
//to the type inferred by the following operation
showType((a == 4) ? exceptionList : errorList);
- 在这里,我想知道是否有某种方法可以编写一个函数,该函数可以打印与编译器为上述操作推断的类型相对应的通用字符串?
- 例如:我觉得推断的类型一定是
List<? extends Throwable>
编译器的类型 - 我也可能错了,但想知道我们如何确定编译器推断的类型?
解决方案
推荐阅读
- c# - 面没有完全绘制和消失
- git - 修改 git 提交,并在一个命令中应用到所有后续分支
- google-bigquery - 标准sql:将数组中的字符串转换为float64
- uwp - 如何授权访问应用程序路径?
- pine-script - 仅绘制最后 2 个连接的摆动高/低(重绘指标)
- raspberry-pi - 如何用一个树莓派制作 10 个设备?
- python - 尝试查找特定范围内的出现次数
- javascript - 在服务器上设置请求后,Cors 仍然阻止请求
- jmeter - 如何使用 Azure Pipeline 在 Jmeter 中传递变量组?
- android - 无法对服务中附加的覆盖窗口使用指纹身份验证