3 ms·
When exactly would you benefit from overloading based on a generic type? How come it is never brought up with Haskell for example, or the other majority of lang
by kaba0 6y ago
When exactly would you benefit from overloading based on a generic type? How come it is never brought up with Haskell for example, or the other majority of languages that employ type erasure?
- eweise 6y agoHaskell has higher kinded types.
- culturedsystems 6y agoYou might want to have something like `String concatenate(List<String> strings)` and `List<T> concatenate(List<List<T>> lists)`. Java won't let you do this because types are erased at compile time, and Java doesn't know exactly what function it's going to call until run time (in order to allow dynamically loading classes). Haskell does allow something similar to this kind of overloading, because Haskell determines what function is going to be called at compile time, before type erasure happens.