Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 6g test.go && 6l test.6 && ./6.out && rm test.6 6.out
- package main
- import "fmt"
- // gives same output with this delcaration:
- // func showObject(o String) {
- func showObject(o Object) {
- switch o.(type) {
- case int:
- fmt.Println("int!")
- case Integer:
- fmt.Println("integer!")
- case String:
- fmt.Println("string!")
- case Object:
- fmt.Println("object!")
- }
- }
- type Object interface{}
- type String Object
- type Integer Object
- func main() {
- a := String("foo")
- showObject(a)
- // outputs: "integer!"
- }
Add Comment
Please, Sign In to add comment