Last active
October 26, 2017 23:47
-
-
Save lamarmarshall/29eafe3a6240ace93a39ae3509aa7839 to your computer and use it in GitHub Desktop.
generic function arguments, interface arguments
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" | |
) | |
func whatami(tp interface{}) { | |
switch tp.(type) { | |
case int: | |
fmt.Println("i am an int") | |
case string: | |
fmt.Println("i am a string") | |
} | |
/* capture the value | |
switch val := tp.(type) { | |
case int: | |
fmt.Println("i am an int", val) | |
case string: | |
fmt.Println("i am a string", val) | |
} | |
*/ | |
} | |
func main() { | |
whatami(25) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment