3 ms·
I made an example of what Im trying to do. https://goplay.tools/snippet/Vj7uVMi0mWn https://goplay.tools/snippet/Vj7uVMi0mWn Basically have two different type
by wara23arish 4y ago
I made an example of what Im trying to do.
https://goplay.tools/snippet/Vj7uVMi0mWn https://goplay.tools/snippet/Vj7uVMi0mWn
Basically have two different types that implement an interface, pass them into a receiver function in a composite type (array,slice).
Part of the issue is that you cant have the receiver function without defining instantiating the type on the receiver Spotter in this case.
- markoman 4y agoYou don't actually have to instantiate the type for a receiver function (i.e., method). There's too much missing from your code for me to understand which direction you're going but you'll likely have to use a constraint for structs which is explained here: https://github.com/akutz/go-generics-the-hard-way/blob/main/04-getting-going/04-structural-constraints.md https://github.com/akutz/go-generics-the-hard-way/blob/main/...