swift将泛型子类强制转换为其超类

时间:2016-02-12 09:47:15

标签: ios swift generics

这是我的代码

class Chair{}
class MyChair:Chair {}

class House<T:Chair> {
}

class MyHouse<D:MyChair>:House<MyChair>{}

现在,如果我尝试以下

var houseClass:AnyObject = MyHouse<MyChair>.self
println(houseClass is House<Chair>.Type)  // return false
println(houseClass is House<MyChair>.Type)  // return true

有人知道原因吗?

0 个答案:

没有答案