Swift通用的奇怪行为

时间:2017-02-03 09:35:51

标签: swift generics

我发现了一种奇怪的快速通用行为:

protocol Textable {}

class Test { 
    init<T: NSObject>(values: [T]) where T: Textable {}
}

func test<T: NSObject>(value: T) where T: Textable {
    let values = [value]
    Test(values: [value]) // Cannot convert value of type '[T]' to expected argument type '[_]'
}

此代码有错误:

  

无法将'[T]'类型的值转换为预期的参数类型'[_]'。

但如果我将Test(values: [value])更改为Test(values: values),则可以正常使用。也许我做错了什么?或者它只是一个快速的错误......

在Swift JIRA创建issue

0 个答案:

没有答案
相关问题