Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Created June 24, 2014 01:31
Show Gist options
  • Save tmtk75/0f726d68cb63756bab6f to your computer and use it in GitHub Desktop.
Save tmtk75/0f726d68cb63756bab6f to your computer and use it in GitHub Desktop.
package main
type A struct {
Name string
}
type B struct {
A
}
type C struct {
*A
}
type Dog interface {
Bark()
}
func (self *A) Bark() {
print(self.Name, " says wow\n")
}
func main() {
a := &A{"taro"}
b := &B{*a}
c := &C{a}
_b := &B{}
_c := &C{}
var ad Dog = a
var bd Dog = b
var cd Dog = c
ad.Bark()
bd.Bark()
cd.Bark()
//b = a // can't assign
print(b.Name, "\n")
print(_b.Name, "\n")
print(_c, "\n")
//print(_c.Name) // panic
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment