这只是一个孤立的例子,可能看起来不太有用,但我还是想知道为什么它不能工作?非常感谢任何见解。
protocol Prot: class {
init()
}
class A: Prot {
required init(){ }
}
struct Client<T: Prot> {
let tau: T.Type
}
if let aTau = A.self as? Prot.Type {
print(aTau === A.self) // ✅
Client(tau: A.self) // ✅
Client(tau: aTau) // ❌
}
错误信息为:
Cannot invoke initializer for type 'Client<_>' with an argument list of type '(tau: Prot.Type)'
Prot
用作符合Prot
的类型。 - Hamish