[swift-evolution] [swift-evolution-announce] [Review] SE-0068: Expanding Swift Self to class members and value types

Erica Sadun erica at ericasadun.com
Mon Apr 25 15:18:58 CDT 2016


On Apr 25, 2016, at 11:18 AM, Michael Peternell via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Is "Self" dynamically dispatched? What would the following program print?
> 
> class A: NSObject {
>    static func myClassName() -> String {
>        return "A"
>    }
>    func hello() -> String {
>        return "I am a \(Self.myClassName())"
>    }
> }
> 
> class B: A {
>    static func myClassName() -> String {
>        return "B"
>    }
> }
> 
> print(B.init().hello())
> 
> Because I think "Self" would only cause confusion if it is statically dispatched. assert(B.init().hello() == "I am a B")
> 
> -Michael


The current Swift will not allow your second example to compile.

-- E

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160425/66707e8c/attachment.html>


More information about the swift-evolution mailing list