3 ms·
Generics are not really the statically typed answer to duck-typing. Subtyping with structural types, such as in TypeScript, is.
by reuben364 5y ago
Generics are not really the statically typed answer to duck-typing. Subtyping with structural types, such as in TypeScript, is.
- eru 5y agoI think the confusion might stem from C++'s templates. Those templates can be used to do something like generics, but they are also basically duck typing at compile time. In Haskell terms, C++'s generics are like typeclass-instances without typeclasses themselves. (I think in Java terms they would be similar to not providing interfaces. But I don't know enough about Java to see whether that's actually true.)