Adding multiple types to collection

I would generally recommend avoiding this, but sometimes it could be neccessary. To add multiple types to a single map you must declare the map to take the interface type. The interface type is comparable to Object in Java. Everyhing is an interface.

package main

import "fmt"

func main(){
    m := map[string]interface{}{
        "test":1,
        "test2":"test",
    }
    fmt.Println(m)
    s := []interface{}{
        "test",
        2,
    }
    fmt.Println(s)
}

See also