5 ms·
"You can accept a struct where an interface is a parameter but you cannot return a struct where an interface is the return type." Possibly I'm misunderstanding
by dfawcus 4y ago
"You can accept a struct where an interface is a parameter but you cannot return a struct where an interface is the return type."
Possibly I'm misunderstanding the complaint, but that is because an interface is a fat pointer, so one returns a pointer to a struct implementing the interface.
https://go.dev/play/p/YOa6NF7rjPF https://go.dev/play/p/YOa6NF7rjPF
- apatheticonion 4y agoIt's more this scenario https://go.dev/play/p/S2yQqriYTtm https://go.dev/play/p/S2yQqriYTtm It's because an interface is structurally evaluated only on variable assignment, but it's not always structurally evaluated which limits its usefulness