Switch cases in Go

Predict the output of the following code snippet.

func main() {
 var X interface{}
 
 switch i := X.(type){
 case nil: 
 fmt.Printf("X is :%T",i) 
 case int: 
 fmt.Printf("X is int") 
 case float64:
 fmt.Printf("X is float64") 
 case func(int) float64:
 fmt.Printf("X is func(int)") 
 case bool, string:
 fmt.Printf("X is bool or string") 
 default:
 fmt.Printf("Don't Know") 
 } 
}
Options
  1. X is int
  2. X is bool or string
  3. X is func(int)
  4. X is :<nil>

Related Posts