Hacker News new | ask | show | jobs
by MereInterest 3680 days ago
Type erasure also makes some forms of function overloading impossible.

    void func(List<ClassA> list);
    void func(List<ClassB> list);
Using type erasure, I cannot specify functions that are overloaded based on the generic type of an argument. To the runtime, both of these accept an argument of type List<Object>, and so it is ambiguous which one to call.

In C++, which does not use type erasure, this sort of function overloading works as expected.