Swift无法将Class <string>理解为Class <anyhashable>

时间:2017-02-02 18:52:42

标签: swift compiler-errors swift3

这是否有充分理由失败:

class Test<T: Hashable> {}

var d: Test<AnyHashable>? = nil
let t = Test<String>()
d = t // Cannot assign value of type 'Test<String>' to type 'Test<AnyHashable>?'

虽然这显然有用吗?

var d: AnyHashable? = nil
let t = "123"
d = t // Works fine

0 个答案:

没有答案