Skip to content

Instantly share code, notes, and snippets.

@j16r
Created November 9, 2015 15:29
Show Gist options
  • Save j16r/0cb202da1d78bce8271f to your computer and use it in GitHub Desktop.
Save j16r/0cb202da1d78bce8271f to your computer and use it in GitHub Desktop.
An array of traits?
package main
import "fmt"
type Trait interface {
String() string
}
type Traitable struct {
}
func (t Traitable) String() string {
return "me!"
}
func main() {
traitables := []Trait{
Traitable{},
}
for _, t := range traitables {
fmt.Println(t.String())
}
}
@j16r
Copy link
Author

j16r commented Nov 9, 2015

This outputs:

me!

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