String { return "Integer" } func alias(a:T...">

General and early binding in Swift 1.2

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 going on, but I don't understand why. Is this by design or a bug? if by design then alias(a) =/= f(a)

, but the definition reads exactly alias(a) = f(a)

!

+3
generics overloading swift


source to share


No one has answered this question yet

See similar questions:

3
Swift generic method must use overloaded generic function

or similar:

1106
Create a generic method limiting T to Enum
1027
How do I create a generic array in Java?
928
How do I call Objective-C code from Swift?
902
# pragma in Swift?
870
Swift beta: sorting arrays
868
How do I use reflection to call a generic method?
703
Swift for loop: for index, item in array?
656
#ifdef Swift replacement
650
How to get an instance of a generics class of type T
642
@selector () in Swift?



All Articles
Loading...
X
Show
Funny
Dev
Pics