Re:A categorized list of all Java and JVM features since JDK...
by kaba0 on Thursday April 01, 2021 @03:25PM
(#26664931)
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?
[ Parent
| on HN ]
Re:A categorized list of all Java and JVM features since JDK...
by culturedsystems on Thursday April 01, 2021 @08:39PM
(#26668007)
You 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.