Created
September 16, 2014 06:42
-
-
Save Kairi/a187717a29621ac9d913 to your computer and use it in GitHub Desktop.
type assertion and switch
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 typeCheck(value interface{}) { | |
| switch t := value.(type) { | |
| case string: | |
| fmt.Println(t , "is string") | |
| case int: | |
| fmt.Println(t, "is int") | |
| } | |
| } | |
| func main() { | |
| typeCheck("Hello World") | |
| typeCheck(123) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment