The usual way to do this is a function or method to convert from []string to []interface{}: https://play.golang.org/p/VW-xs6E9xul
The correct approach is probably something different than "func PrintAll(vals []interface{})". What are you trying to do? Matt On Tuesday, February 27, 2018 at 9:25:07 AM UTC-6, k1at...@gmail.com wrote: > > *Hello* > > *A beginner question :* > > *Why doesn't work this :* > > package main > > import ( > "fmt" > ) > > func PrintAll(vals []interface{}) { > for _, val := range vals { > fmt.Println(val) > } > } > > func main() { > names := []string{"stanley", "david", "oscar"} > <-----error > PrintAll(names) > } > > > > *and Why does it work? :* > > > > > package main > > import ( > "fmt" > ) > > func PrintAll(vals interface{}) { > fmt.Println(vals) > } > > func main() { > names := "stanley" <---why not > error here > PrintAll(names) > } > > > *The only difference is : first sample is slice of string , second is only a > string* > > > *thank you in advance Attila* > > > > > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.