Skip to content

Instantly share code, notes, and snippets.

@brpaz
Created March 16, 2019 10:04
Show Gist options
  • Save brpaz/e7983b31cf3a0d33e0819df1ee294391 to your computer and use it in GitHub Desktop.
Save brpaz/e7983b31cf3a0d33e0819df1ee294391 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
var i interface{} = "hello"
s := i.(string)
fmt.Println(s)
s, ok := i.(string)
fmt.Println(s, ok)
f, ok := i.(float64)
fmt.Println(f, ok)
f = i.(float64) // panic
fmt.Println(f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment