2 ms·
> This is a point that folks new to Go often miss. It's still not true that interfaces are generics, though. > Aside from the fact that Java didn't add generi
by pcwalton 13y ago
> This is a point that folks new to Go often miss.
It's still not true that interfaces are generics, though.
> Aside from the fact that Java didn't add generics until 1.5 (if I remember correctly)
But that was a big mistake in Java: they had to implement them using type erasure and primitives didn't work with them (due to backwards compatibility), and they had to duplicate the collections library to have non-generic and generic collections (again due to backwards compatibility).
> [2] I'm reminded of how Haskell has both "class" and "return" as keywords that have nothing to do with their Java counterparts - I think Go's "interface" is along the same lines - it's the same identifier/term, but a very different meaning.
I don't think the difference is that stark—interfaces in Java and interfaces in Go are essentially the same thing. The facts that all values can be wrapped in an interface (which is also true for C#, I believe) and that interface matching is structural instead of nominal are relatively minor.