You can omit type arguments in calling code when the Go compiler can infer the
types you want to use. The compiler infers type arguments from the types of
function arguments.
Note that this isn’t always possible. For example, if you needed to call a
generic function that had no arguments, you would need to include the type
arguments in the function call.
If you want to change selection, open document below and click on "Move attachment"
Tutorial: Getting started with generics - The Go Programming Languagethis section, you’ll add a modified version of the generic function call, making a small change to simplify the calling code. You’ll remove the type arguments, which aren’t needed in this case. <span>You can omit type arguments in calling code when the Go compiler can infer the types you want to use. The compiler infers type arguments from the types of function arguments. Note that this isn’t always possible. For example, if you needed to call a generic function that had no arguments, you would need to include the type arguments in the function call. Write the code In main.go, beneath the code you already have, paste the following code. fmt.Printf("Generic Sums, type parameters inferred: %v and %v\n", SumIntsOrFloats(ints), SumIntsO Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details