Skip to content

Instantly share code, notes, and snippets.

@jmsdnns
Last active August 30, 2015 02:31
Show Gist options
  • Save jmsdnns/78617a551fd2cb773dea to your computer and use it in GitHub Desktop.
Save jmsdnns/78617a551fd2cb773dea to your computer and use it in GitHub Desktop.
Q: What does it mean that Go doesn't support Generics? -- A: This snippet.
package main
import (
"fmt"
)
type Whatever interface {
foo()
}
// This is not allowed.
//func (w Whatever) foo() {
// fmt.Println("w.foo")
//}
type SomethingElse struct {
s string
}
func (b SomethingElse) foo() {
fmt.Println("b.foo")
}
func DoSomethingWithWhatever(w Whatever) {
w.foo()
}
func main() {
s := SomethingElse{}
DoSomethingWithWhatever(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment