4 ms·
As a Java end user I'm really glad that method overloading exists. The two largest libraries I ever built would have been huge messes without overloading. But I
by nradov 6y ago
As a Java end user I'm really glad that method overloading exists. The two largest libraries I ever built would have been huge messes without overloading. But I take your point that method overloading might be a net negative for the Java platform as a whole.
- recursivedoubts 6y agoYes, java would be a mess without overloading (particularly for telescoping args), but that's because it doesn't include other, simpler features that address the same problems. Namely: - default parameter values - union types - names arguments I would also throw in list and map literals, to do away with something like varargs. All of these are much simpler, implementation-wise, than method overloading. None would require anywhere near the compiler or bytecode-level support that method overloading does. It just has a very low power to weight ratio, when other langauge features are considered. And, unfortunately, it makes implementing all those other features (useful on their own) extremely difficult.
- layer8 6y agoI don‘t really see a significant difference between overloaded methods and a single method with a sum type (where, in the general case, the sum is over the parameter-list tuple types of the overloaded methods). One can interpret the former as syntactic sugar for the latter.
- recursivedoubts 6y agoStatic vs dynamic dispatch, to start with. You need default values (and ideally named parameters) to really make them equivalent, but yes, both address a similar set of developer needs. The java implementation, where it bleeds into bytecode and method scoring in insane ways, is particularly unfortunate.
- diroussel 6y agoBut it’s not actually syntactic sugar in java. There is a whole concept of type-signature which is part of method look up. Without overloading lookup would just be via name.
- zelphirkalt 6y agoOn the other hand languages get by completely without method overloading and use for example default parameter values. I don not think that method overloading is necessarily required to not make a mess.
- WalterBright 6y agoOverloading is very valuable, especially in conjunction with generic code. But unfortunately, it is way overused. It takes a long time to develop good judgement. I'm still working on it.