Last active
August 29, 2015 14:00
-
-
Save rosylilly/11406316 to your computer and use it in GitHub Desktop.
これ DCI なんでは?
This file contains 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 User struct { | |
Name string | |
} | |
func (u *User) Say() { | |
fmt.Printf("I'm %s\n", u.Name) | |
} | |
type Admin User | |
func (a *Admin) Hello() { | |
((*User)(a)).Say() | |
fmt.Printf("Hello %s\n", a.Name) | |
} | |
func main() { | |
user := &User{"rosylilly"} | |
admin := (*Admin)(user) | |
admin.Hello() | |
fmt.Printf("%p %p", admin, user) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ポインタの値は変わってないし、コピーが走ってるってこともなさそうなので、本当にコンパイル時のヒントくらいにしか扱われてないのかな?
http://play.golang.org/p/iEMkDv7CxP