On Tue, Apr 9, 2024 at 9:41 AM Mihai Barbu <ad...@hopz.com> wrote: > > I need to call some generic functions with types that are now known at > compile time. Is it possible to do this? > See the code below (vastly reduced). > > // fv is a function that returns an unknown type > func Do(fv reflect.Value){ > // get the first returned type by function fv > vt := fv.Type().Out(0) > // how to call `Hello` with `v` ? > // Obviously the code below is incorrect > Hello[vt]() > } > > func Hello[T any](){ > // do something with T > json.Marshal(new(T)) > }
This is not possible. Sorry. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVTE26WbM7UsLtuyHNvOSmELMf1ZMgVt%3DycwFq9K4o3uQ%40mail.gmail.com.