func foo(args ...string) { for _, arg := range args { fmt.Println(arg) } } typeFoo := reflect.TypeOf(foo) fmt.Println(typeFoo.IsVariadic()) // Output: true
func bar(a, b string) { fmt.Println(a, b) } typeBar := reflect.TypeOf(bar) fmt.Println(typeBar.IsVariadic()) // Output: falseIn this example, we define a function `bar` that is not variadic, meaning it can only accept two string arguments. We again use the reflect package to get the type of `bar` and check if it is variadic using the IsVariadic method. The output of this code will be false. Overall, the reflect package is useful when working with functions and their types, and the IsVariadic method can help determine whether a function can accept a variable number of arguments or not.