3 ms·
This has little (nothing?) to do with generics, though. This is an example of function (name) overloading.
by Koshkin 4y ago
This has little (nothing?) to do with generics, though. This is an example of function (name) overloading.
- tialaramex 4y agoThe technical term for this feature in this context is "ad hoc polymorphism". It's polymorphic because it only allows you to specify different types, you can't just go around making six different foo() methods that all take a string - that doesn't work because the compiler can't tell which one you wanted, and it's ad hoc because you can just fill out whatever you want in each version. The negative consequence of being ad hoc is that there's not even a very strong implication beyond the name that these different functions all do the same thing, and sure enough they often don't. So now either your users must read your documentation very carefully, or sometimes they will have unhappy accidents. This is made worse in many modern languages with type inference where your users may be mistaken about which of the functions they're actually calling since they don't always know the type of anything anyway... Ad hoc polymorphism is over-used because it is relatively cheap to implement, and it's cheap to add more of these overrides later.
- Koshkin 4y agoWell, having methods in different classes that happen to share the same name is also an example of that, and so it cannot be avoided (not in practice, anyway).