Java – Multiple Dispatch vs. Function Overloading

javamultiple-dispatch

I'm trying to understand the difference (if any) between the two.

According to the Wikipedia page for Multiple Dispatch it is synonymous with Function Overloading, but then later on goes on to say:

In a language with only single dispatch, such as Java […]

which seems like a contradiction, since Java does support function overloading.

So which is it? Is Multiple Dispatch different from Function Overloading, or is the article wrong in claiming that Java does not support Multible Dispatch?

Best Answer

Multiple dispatch is not (always) the same as function overloading, although they do bear some similarities. And Java does not support multiple dispatch.

In statically typed languages, including Java, the biggest difference between dispatch and overloading is that overloading is based on the static type of parameters (i.e. the choice of which method is actually called is decided compile-time), while dispatch is based on the dynamic types (i.e. the decision is made runtime). (Such languages usually don't support multiple dispatch.)

But then again, this may be a question of terminology. In dynamically typed languages, dispatch and overloading indeed seem to boil down to the same thing.