Skip to content

Instantly share code, notes, and snippets.

@guesslin
Created September 6, 2017 08:13
Show Gist options
  • Save guesslin/9cd4e3e617b332a05331304113e78105 to your computer and use it in GitHub Desktop.
Save guesslin/9cd4e3e617b332a05331304113e78105 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type Small interface {
Foo(int) int
}
type Big interface {
Foo(int) int
Boo(string) string
}
type Qoo struct {
Name string
Age int
}
func (q *Qoo) Foo(i int) int {
q.Age += i
return q.Age
}
func (q *Qoo) Boo(s string) string {
q.Name += s
return q.Name
}
func NewSmall(age int) Small {
return &Qoo{
Age: age,
Name: "Hello ",
}
}
func main() {
s := NewSmall(10)
fmt.Println("Small")
if b, ok := s.(Big); ok {
fmt.Println("Big")
fmt.Println(b.Boo("World"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment