问题
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