Generic and (early?) binding in Swift 1.2

你说的曾经没有我的故事 提交于 2019-12-22 10:53:36

问题


func f<T>(a:T)->String { return "Generic" }
func f(a:Int)->String { return "Integer" }
func alias<T>(a:T)->String { return f(a) }

f(1) // "Integer"
f("string") // "Generic"

alias(1) // "Generic" (shouldn't be "Integer" ?)
alias("string") // "Generic"

I understand that some form of early (static) binding is happening but I don't understand why. Is it by design or a bug? if by design then alias(a) =/= f(a) but the definition reads exactly alias(a) = f(a) !

来源:https://stackoverflow.com/questions/32606334/generic-and-early-binding-in-swift-1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!