Hacker News new | ask | show | jobs
by dfawcus 1357 days 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

1 comments

It's more this scenario 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