Skip to content

Instantly share code, notes, and snippets.

@xbeta
Created March 7, 2015 07:49
Show Gist options
  • Save xbeta/29bc926fa42d522810cd to your computer and use it in GitHub Desktop.
Save xbeta/29bc926fa42d522810cd to your computer and use it in GitHub Desktop.
Golang's "generic"
package main
import "fmt"
type Integer16 int16
type Integer32 int32
type Calculator interface {
Calculate()
}
func (i Integer16) Calculate() { /* behavior here */ }
func (i Integer32) Calculate() { /* behavior here */ }
func main() {
container := []Calculator{Integer16(1),Integer32(2)}
fmt.Println(container)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment