SHARE
TWEET

Untitled

a guest Mar 21st, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var i interface{} = "hello"
  7.  
  8.     s := i.(string)
  9.     fmt.Println(s)
  10.  
  11.     s, ok := i.(string)
  12.     fmt.Println(s, ok)
  13.  
  14.     f, ok := i.(float64)
  15.     fmt.Println(f, ok)
  16.  
  17.     f = i.(float64) // panic
  18.     fmt.Println(f)
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top