August 2021
Beginner
112 pages
1h 23m
English
| Puzzle 24 | Fun with Flags |
| | package main |
| | |
| | import ( |
| | "fmt" |
| | ) |
| | |
| | type Flag int |
| | |
| | func main() { |
| | var i interface{} = 3 |
| | f := i.(Flag) |
| | fmt.Println(f) |
| | } |
Guess the Output | |
|---|---|
|
|
Try to guess what the output is before moving to the next page. |
This code will panic.
Even though Flag is basically an int, the Go compiler sees it as a distinct type, and the type assertion (i.(Flag)) will panic. This is another case where you can use ...
Read now
Unlock full access