dimanche 23 juillet 2023

How Using Golang Reflect Type to Instantiate Generic Type Seeding From It

Having a generic interface

type G[T any] interface {
...
}

and reflect.Type t, how to instantiate another reflect.Type which would represent actually G[t]

Eventually the t it self should be matched against G[t]

func ImplementsG(t reflect.Type) bool {
    var gType reflect.Type = ... // instantiate(G, t)

    return t.Implements(gType)
}




Aucun commentaire:

Enregistrer un commentaire