Skip to content

Instantly share code, notes, and snippets.

@Gernot
Created April 22, 2021 11:57
Show Gist options
  • Save Gernot/9f3595195f37ecb6bb6f2b1ef9160fb6 to your computer and use it in GitHub Desktop.
Save Gernot/9f3595195f37ecb6bb6f2b1ef9160fb6 to your computer and use it in GitHub Desktop.
What is happening here?
import Foundation
class Foo<Value> {
init(value: Value) {
self.value = value
}
let value: Value
func doSomething() {
print("Generic")
}
func doSomething() where Value: FloatingPoint {
print("Floating point")
}
}
class Bar<Value>: Foo<Value> {
func doAnotherThing() {
doSomething()
}
}
Foo(value: 1.0).doSomething() //Floating point
Foo(value: 1).doSomething() //Generic
Bar(value: 1.0).doSomething() //Floating point
Bar(value: 1).doSomething() //Generic
Bar(value: 1.0).doAnotherThing() //Generic (This should be "Floating Point"!!!!)
Bar(value: 1).doAnotherThing() //Generic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment