3 ms·
Huh? You can put concrete types in interface definitions as of 1.18. See the spec: https://go.dev/ref/spec#Interface_types https://go.dev/ref/spec#Interface_ty
by riwsky 4y ago
Huh?
You can put concrete types in interface definitions as of 1.18. See the spec: https://go.dev/ref/spec#Interface_types https://go.dev/ref/spec#Interface_types
- jrockway 4y agoThe spec does say that. You can put them in the interface, but you can't use the interface. Try it: https://go.dev/play/p/9ptEd8zasML https://go.dev/play/p/9ptEd8zasML
- riwsky 4y agoYou can put them in the interface, and then you can use the interface as a type constraint for generics: https://go.dev/play/p/U25AzZndz-7 https://go.dev/play/p/U25AzZndz-7 If you wanted to argue that you can't use it everywhere you could use an interface before, that'd be all well and good—but your assertion > you can't actually put concrete types in interface{} definitions is just incorrect, in a way that lead you to misunderstand the article.