FAQ
Hi all,

I am just curious since interface{} can accept any type, why []interface{}
can't accept []int? Lile this:

func f(s []interface{}) {
fmt.Println(s)
}

func main() {
s := []int{1, 2}
f(s)
}


The compiler complains:

cannot use s (type []int) as type []interface {} in argument to f


Except define s as []interface{}, is there any method to fix this issue?

Thanks very much in advance!

Best Regards
Nan Xiao

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 4, '16 at 2:20a
activeMay 4, '16 at 2:26a
posts2
users2
websitegolang.org

2 users in discussion

Nan Xiao: 1 post Jesse McNelis: 1 post

People

Translate

site design / logo © 2021 Grokbase