Generic and (early?) binding in Swift 1.2

2019-05-17 13:59发布

问题:

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) !