I don’t understand the overloading in Java. Is there a relation with polymorphism ? It seems very abstract for me.
I come more from Javascript language ? Would this apply so in Javascript ?
I don’t understand the overloading in Java. Is there a relation with polymorphism ?
Share
Overloading means that the same method name can be defined with more than one signature — the list of formal parameters (and their types).
Overloading means different things in different languages. Java is strongly typed (some might say “fiercely typed” in fact). It just means that there can be different versions of a function and the compiler can tell which one is intended by looking at the types of parameters in a call to the function (method).
JavaScript is not like that; the formal parameters to a function are just references by name in the function body, but otherwise there’s nothing special about them and any function can be called with any arguments and any number of them.
Some languages use “overloading” as a runtime concept. In Erlang, it’s not the types of arguments that matter when picking from several alternative versions of a function; it’s the values.
edit — @MarkoTopolnik points out that the issue isn’t so much about the “strength” (or “ferocity” 🙂 of the type system, but about how static it is. Java insists on types being explicitly declared pretty much everywhere, while JavaScript (excepting some of the new typed array constructs) doesn’t.