Skip to content

Instantly share code, notes, and snippets.

@pcantrell
Last active June 16, 2017 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcantrell/7d1913585d1f7fc3f578aed7ea68cc8f to your computer and use it in GitHub Desktop.
Save pcantrell/7d1913585d1f7fc3f578aed7ea68cc8f to your computer and use it in GitHub Desktop.
public protocol P {
func foo()
}
public protocol Q: P {
}
extension Q {
final func foo() { … }
}
class Thingy: P {
func foo() { … } // OK!
}
class Dingy: Q {
func foo() { … } // Not allowed, because final
}
let p: P = …
p.foo() // Needs dynamic dispatch, because P is public & other module could provide other impl
let q: Q = …
q.foo() // Can use static dispatch iff extensions allow final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment