Mastering-Go-Second-Edition/ch07/assertion.go
Mihalis Tsoukalos 41e952363f Minor typo
2019-03-08 21:53:09 +02:00

27 lines
338 B
Go

package main
import (
"fmt"
)
func main() {
var myInt interface{} = 123
k, ok := myInt.(int)
if ok {
fmt.Println("Success:", k)
}
v, ok := myInt.(float64)
if ok {
fmt.Println(v)
} else {
fmt.Println("Failed without panicking!")
}
i := myInt.(int)
fmt.Println("No checking:", i)
j := myInt.(bool)
fmt.Println(j)
}