Created
November 22, 2016 21:43
-
-
Save lucasrpb/a50129d366ad1c70eb7e6aea935e8bd7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
) | |
type Parenter interface { | |
super() interface{} | |
} | |
type I interface { | |
Parenter | |
m() | |
} | |
type A struct { | |
Name string | |
} | |
func(a A) m() { | |
fmt.Println("Hi from A!") | |
} | |
type B struct { | |
A | |
} | |
func(b B) m() { | |
fmt.Println("Hi from B!") | |
} | |
func(b B) super() interface{} { | |
return b.A | |
} | |
func f(i I){ | |
i.m() | |
fmt.Println(i.super().(A).Name) | |
} | |
func f2(i A){ | |
i.m() | |
fmt.Println(i.Name) | |
} | |
func f3(b B){ | |
a := b.super().(A) | |
b.m() | |
fmt.Println(a.Name) | |
} | |
func f4(x interface{}){ | |
i := x.(I) | |
a := i.super().(A) | |
b := x.(B) | |
b.m() | |
fmt.Println(a.Name) | |
} | |
func main() { | |
b := B{A{"luke"}} | |
f(b) | |
f2(b.A) | |
f3(b) | |
f4(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment