go - How to build mixed array -


in ruby can created array filled types:

[1, 'hello', :world] # [fixnum, string, symbol] => [1, "hello", :here] 

how implement similar array filled mixed types in go?

how declare array?

you can via empty interface - interface{}:

arr := make([]interface{}, 0)  arr = append(arr, "asdfs") arr = append(arr, 5) 

or in literal form:

arr := []interface{}{"asdfs", 5} 

whenever want use value of array need use type assertion.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -