Generics - method won' compile

This works:

func addThem[N int](a N, b N) N{
	c := a + b
	return c

This won’t compile:

func (c Client) FindAllTransactions[S any](dbUniqueIdentifier database.DBUniqueIdentifier, schema S) (interface{}, error)...

interface method must have no type parameters

I have installed the latest version of Go

I have to say I didn’t understand why they won’t support generics for interface functions. Seems very inconsistent. But I guess that’s life. Have to try to implement using interfaces and reflection.

1 Like

In case you didn’t see it, a couple of implementation difficulties are mentioned here Type Parameters Proposal

1 Like

I find you can pull the multi type parameter functionality out of the interface or structure and create a multi type parameter function which accepts the the generic interface or structure.

Actually your post addresses a real issue with generics in GoLang and I’d love to see some real work-a-rounds.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.