Swift文档说:
类不能将不透明类型用作非最终方法的返回类型。
但是,这段代码编译成功:
protocol P {}
class A:P {}
class B {
func myFunc() -> some P {
return A()
}
}文档中的意思是什么?
发布于 2020-01-22 19:13:29
确切地说,上面写的是..。在你的游乐场里试试
protocol P {}
class A:P {}
class B {
func myFunc() -> some P {
return A()
}
}
class C: B {
func myFunc() -> some P {
return A()
}
}
let b = B()
let c = C()
let ab = b.myFunc()
let ac = c.myFunc()你收到
Playground execution failed:
error: Untitled Page 4.xcplaygroundpage:21:10: error: ambiguous use of 'myFunc()'
let ac = c.myFunc()
^
Untitled Page 4.xcplaygroundpage:13:10: note: found this candidate
func myFunc() -> some P {
^
Untitled Page 4.xcplaygroundpage:7:8: note: found this candidate
func myFunc() -> some P {是的我知道..。‘一些’仍然是非常新的,将在下一个版本中看到:-)
https://stackoverflow.com/questions/59864035
复制相似问题