Advertisement
cwchen

[Go] Type assertion.

Oct 7th, 2017
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.19 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. func main() {
  8.     var im interface{}
  9.     var in interface{}
  10.  
  11.     im = 3
  12.     in = 2
  13.  
  14.     // type assertion
  15.     m := im.(int)
  16.     n := in.(int)
  17.  
  18.     fmt.Println(m + n)
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement