I'm very new in Go, and I came from Ruby. So...
can I build array what includes different types
[1, 2, "apple", true]
Sorry if it's stupid question.
Thanks.
You can do this by making a slice of interface{}
type. For example:
func main() {
arr := []interface{}{1, 2, "apple", true}
fmt.Println(arr)
// however, now you need to use type assertion access elements
i := arr[0].(int)
fmt.Printf("i: %d, i type: %T
", i, i)
s := arr[2].(string)
fmt.Printf("b: %s, i type: %T
", s, s)
}
Read more about this here.