I'm refactoring some of my code now that Go 1.18 is out with the new Generics feature. I've created a generic interface i.e
type IExample[T any] interface{
ExampleFunc(ex T) T
}
Somewhere in my code, I want to store several implementations of this interface in a map and use them generically in my code.
mapping := map[string]IExample{
// .......
}
But the go compiler throws this error cannot use generic type types.SettingsAdapter[T any] without instantiation
So, I tried adding any
to the generic type
mapping := map[string]IExample[any]{
// .......
}
Which resulted in the following error
IExample[any] does not implement IExampleImpl[ExampleT]
At this point, I feel that there's something I'm missing while implementing the code, or that I'm just using this feature in a way that it wasn't meant to be used.
Thanks :)