Created
March 7, 2015 07:49
-
-
Save xbeta/29bc926fa42d522810cd to your computer and use it in GitHub Desktop.
Golang's "generic"
This file contains hidden or 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 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