peterbe / govspy

Go vs. Python
http://govspy.peterbe.com
116 stars 14 forks source link

Go: varying types in variadic functions #8

Open plunkets opened 6 years ago

plunkets commented 6 years ago

It is possible in Go, with an empty interface.

package main
func main() {
    i := 2.5
    j := "test"
    k := true

    varia(i, j, k)

}
func varia(arguments ...interface{}) {
    for _, v := range arguments {
        fmt.Print(reflect.TypeOf(v))
    }
}

Output: float64 string bool