【发布时间】:2015-04-03 18:43:28
【问题描述】:
以下 Swift 代码无法编译:
class Entity {
}
class EntityConverter<T: Entity> {
}
class GetEntityServerAction<T: Entity, C: EntityConverter<T>> {
}
class GetEntityListServerAction<T: Entity, C: EntityConverter<T>>: GetEntityServerAction<T, C> {
}
出现错误:
Type 'C' does not inherit from 'EntityConverter<T>'
对于GetEntityListServerAction 类定义。
由于某些原因,编译器看不到 C 参数的定义就像继承它想要的完全相同的类型。
对于那些习惯于在 Java 或 C# 中使用复杂的泛型层次结构但 Swift 编译器确实不喜欢的人来说,代码应该看起来相当简单。
【问题讨论】:
标签: swift generics inheritance compiler-errors