Direct comparison of Go interface{} to built-in types: Why does this work?
<p>Why does the following Go code work? </p>

<p>That is, since the types of <code>f</code> and <code>b</code> are <code>interface{}</code> (and not any of <code>bool</code>, <code>int</code> or <code>string</code>), how is it possible for me to get away with <em>not</em> casting or type-asserting <code>f</code> and <code>b</code> in each of the three <code>if</code> statements?</p>

<pre><code>package main

import (
    "fmt"
    "reflect"
)

func foop(p map[string]interface{}) {
    p["foo"] = true
}

func barp(p map[string]interface{}) {
    p["bar"] = 17
}

func foop2(p map[string]interface{}) {
    p["foo"] = "blah"
}

func main() {
    p := make(map[string]interface{})
    fmt.Printf("%v\n", p)

    foop(p)
    barp(p)
    f := p["foo"]
    b := p["bar"]
    fmt.Printf("f: %T\n", f)
    if f == true {
        fmt.Println("ok")
    }
    fmt.Printf("b: %T\n", b)
    if b == 17 {
        fmt.Println("ok")
    }

    foop2(p)
    f = p["foo"]
    if f == "blah" {
        fmt.Println("ok")
    }
    fmt.Printf("f: %T\n", f)
    fmt.Printf("f: %s\n", reflect.TypeOf(f))
}
</code></pre>

<p>(Go Playground: <a href="https://play.golang.org/p/kPi25yW6tF" rel="nofollow">https://play.golang.org/p/kPi25yW6tF</a>)</p>