4 ms·
I think in many cases you don't need generics because you can use the interface mechanism instead. The way Go does it is a bit confusing at first, so I suspect
by poorelise 13y ago
I think in many cases you don't need generics because you can use the interface mechanism instead. The way Go does it is a bit confusing at first, so I suspect many Go newcomers don't really understand they could have used it.
As an example look into the way sorting is implemented in the standard library: http://golang.org/pkg/sort/ http://golang.org/pkg/sort/
I had to look at this example for a long time to get it... And now I have forgotten it again since it was months ago :-(
I still thought it requires too many lines to sort stuff, but it is doable.
- frou_dh 13y agoThat's effectively subtype polymorphism, while generics are parametric polymorphism. Many languages (including Java) make use of both.