Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- func main() {
- var t interface{}
- t = 3
- switch t := t.(type) {
- default:
- fmt.Printf("unexpected type %T\n", t) // %T prints whatever type t has
- case bool:
- fmt.Printf("boolean %t\n", t) // t has type bool
- case int:
- fmt.Printf("integer %d\n", t) // t has type int
- case *bool:
- fmt.Printf("pointer to boolean %t\n", *t) // t has type *bool
- case *int:
- fmt.Printf("pointer to integer %d\n", *t) // t has type *int
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement