[Go] Solve the empty interface interface{} cannot use (type []string) as type []interface {}

Empty interface{}

Can store any type of data

But when working with slices and maps, pay attention

[]interface{} or map[string]interface{}

 

May make this mistake cannot use (type []string) as type []interface {}

You cannot convert []T to []interface, nor can you convert map[string]T to map[string]interface{}

 

The Go language specification does not allow this because the two types do not have the same representation in memory.

Need to define separately []interface{} map[string]interface{}

Copy the element you want to convert to the above type

 For example, the following error:

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *