Last active
January 14, 2016 11:23
-
-
Save mitsuse/3b3bbab538d51e9252cc to your computer and use it in GitHub Desktop.
Example: Automatic initializer inheritance doesn't work for generic types.
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 Node<T> { | |
let value: T | |
init(value: T) { | |
self.value = value | |
} | |
} | |
class Terminal<T>: Node<T> { | |
} | |
// OK | |
let node = Node(value: "node") | |
// error: 'Terminal<T>' cannot be constructed because it has no accessible initializers | |
let terminal = Terminal(value: "terminal") |
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 Node<T> { | |
let value: T | |
init(value: T) { | |
self.value = value | |
} | |
} | |
class Terminal<T>: Node<T> { | |
override init(value: T) { | |
super.init(value: value) | |
} | |
} | |
// OK | |
let node = Node(value: "node") | |
// OK | |
let terminal = Terminal(value: "terminal") |
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 Node { | |
let value: String | |
init(value: String) { | |
self.value = value | |
} | |
} | |
class Terminal: Node { | |
} | |
// OK | |
let node = Node(value: "node") | |
// OK | |
let terminal = Terminal(value: "terminal") |
Author
mitsuse
commented
Jan 14, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment