generics - 扩展特征不匹配的 Groovy 泛型类型 - 不是有界参数的有效替代品
问题描述
下面的代码不能在 Groovy 3.0.4 中编译(尽管它在 Groovy 2.5.0 及更低版本中很好)
Factory<SomeImpl> f = new Factory<>();
trait Base {}
class SomeImpl implements Base {}
class Factory<T extends Base> {}
我得到的确切错误是:
The type SomeImpl is not a valid substitute for the bounded parameter <T extends Base> @ line 1, column 9.
Factory<SomeImpl> f = new Factory<>();
将Base从trait更改为interface允许按预期编译代码并且它可以工作(就像在 Java 中一样)。
trait 是否与不允许我们进行此类构造的接口有所不同?还是最近的 groovy 版本中的错误?
解决方案
推荐阅读
- flutter - 颤振,火力基地。我想显示除电子邮件和密码以外的注册表单数据并连接到唯一的 uid
- javascript - 当用户添加到订单时,无法将商品推送到购物车
- java - 从 Firebase 数据库中读取
- python - 使用枕头调整上传到 s3 的图像大小
- python - bash脚本将整数作为参数并添加它们
- ajax - 为什么在编辑项目后我的数据会附加到我的 url?
- maven - 是否可以在父 pom 中指定 pluginManagement?
- javascript - 如何将此原始代码放入
正确标记?
- rust - Reading ZIP file in Rust causes data owned by the current function
- android - Chaining requests in Retrofit and RxJava