Advertisement
cwchen

[Go] Void interface demo.

Oct 7th, 2017
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.25 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. func main() {
  8.     var v interface{}
  9.  
  10.     // v is an integer.
  11.     v = 1
  12.     fmt.Println(v)
  13.  
  14.     // v becomes a string now.
  15.     v = "Hello"
  16.     fmt.Println(v)
  17.  
  18.     // v becomes a boolean value now.
  19.     v = true
  20.     fmt.Println(v)
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement