1

In Golang 1.18 I can do this:

func foo1[T any](items ...T) {
    // do something
}

func foo2(items ...interface{}) {
    // do something
}

Both of these appear to accept a list of objects whose type is not known by the function itself. Is there something I'm missing here?

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Woody1193
  • 7,252
  • 5
  • 40
  • 90
  • 2
    The main difference in **varargs** is that `...T` is **one** type, and after instantiation `foo1` will accept an arbitrary number of params of the same type. Whereas `...interface{}` accepts an arbitrary number of possibly different types, since all types can be assigned to the empty interface. For all other intents and purposes, `any` is a type alias of `interface{}` – blackgreen May 18 '22 at 06:15

0 Answers0