FAQ
package main

import (
"fmt"
"testing"
)

func PrintStrings(ifs []interface{}) {
fmt.Println(ifs)
}
func TestString(t *testing.T) {
PrintStrings([]string{"1", "2"})
}

Above code compiled to return the following error

.\string_test.go:12: cannot use []string literal (type []string) as type
[]interface {} in function argument
FAIL bug [build failed]

--

Search Discussions

  • Dave Cheney at Jan 5, 2013 at 5:15 am
    http://golang.org/doc/go_faq.html#convert_slice_of_interface
    On Sat, Jan 5, 2013 at 4:10 PM, runner mei wrote:
    package main

    import (
    "fmt"
    "testing"
    )

    func PrintStrings(ifs []interface{}) {
    fmt.Println(ifs)
    }
    func TestString(t *testing.T) {
    PrintStrings([]string{"1", "2"})
    }

    Above code compiled to return the following error

    .\string_test.go:12: cannot use []string literal (type []string) as type
    []interface {} in function argument
    FAIL bug [build failed]

    --
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 5, '13 at 5:15a
activeJan 5, '13 at 5:16a
posts2
users2
websitegolang.org

2 users in discussion

Dave Cheney: 1 post Runner mei: 1 post

People

Translate

site design / logo © 2021 Grokbase