Created
April 21, 2015 14:00
-
-
Save norio-nomura/cb58213b9a78f74927d3 to your computer and use it in GitHub Desktop.
#Swift ジェネリックでは無いクラスのジェネリックなメソッドを、ジェネリックなサブクラスからオーバーライド出来ない罠にはまった。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C { | |
func f<T>(v: T) -> String { | |
return "C(\(v))" | |
} | |
func callf() -> String{ | |
return f("test") | |
} | |
} | |
class D<U>: C { | |
func f<T>(v: T) -> String {// swift compiler never warn missing 'override' keyword, and not allow placing 'override' keyword. | |
return "D(\(v))" | |
} | |
} | |
let d = D<String>() | |
d.callf() // "C(test)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://devforums.apple.com/thread/268824