Guest User

Untitled

a guest
Jan 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. // 6g test.go && 6l test.6 && ./6.out && rm test.6 6.out
  2.  
  3. package main
  4.  
  5. import "fmt"
  6.  
  7. // gives same output with this delcaration:
  8. // func showObject(o String) {
  9.  
  10. func showObject(o Object) {
  11. switch o.(type) {
  12. case int:
  13. fmt.Println("int!")
  14. case Integer:
  15. fmt.Println("integer!")
  16. case String:
  17. fmt.Println("string!")
  18. case Object:
  19. fmt.Println("object!")
  20. }
  21. }
  22.  
  23. type Object interface{}
  24. type String Object
  25. type Integer Object
  26.  
  27. func main() {
  28. a := String("foo")
  29. showObject(a)
  30.  
  31. // outputs: "integer!"
  32. }
Add Comment
Please, Sign In to add comment