Last active
August 30, 2015 02:31
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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