Avatar
norio_nomura 4/12/2018 1:05 AM
@swiftbot protocol Widget { func print() func clone() -> Self } extension Widget { func print() { Swift.print("a widget of type \(Self.self)") } func clone() -> Self { return self } } class Box<Element> : Widget { init(value: Element) { self.contents = value } let contents: Element // Default implementation of print() is OK! // You must define this, or conformance checking fails on Swift 4.0.x: // func clone() -> Self { return self } } class Crate<T> : Box<T> { override init(value: T) { super.init(value: value) } } let c = Crate<Int>(value: 3) c.print() // prints: a widget of type Crate<Int>