Skip to content

Instantly share code, notes, and snippets.

@rosylilly
Last active August 29, 2015 14:00
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 rosylilly/11406316 to your computer and use it in GitHub Desktop.
Save rosylilly/11406316 to your computer and use it in GitHub Desktop.
これ DCI なんでは?
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)
}
@rosylilly
Copy link
Author

ポインタの値は変わってないし、コピーが走ってるってこともなさそうなので、本当にコンパイル時のヒントくらいにしか扱われてないのかな?

http://play.golang.org/p/iEMkDv7CxP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment