# In what sense if any does java have multiple dispatch?

I'm trying to get my head around the difference between message passing (with which we are all familiar as by far the most common form of object orientation today) vs generic functions as implemented in CLOS (Common Lisp Object System).

In what sense is it possible to say java has a kind of multiple-dispatch system due to method overloading?

To sketch my understanding, in message passing you might do:

tell obja move objb
tell objb move obja


but where the function is first class and not in any object, you might do:

move obja objb


The part I do think I understand is that with generics there is no dilemma on where to place a function, whereas in message passing you may have to arbitrarily choose which class to put a function on, then just remember which one you put it on. With message passing, if you want to be able to call the behaviour from either, you have to duplicate the code (yes I know there are ways round that, but that's not the point).

I'm not sure I'm really getting the rest of how generics are different yet.

I just found a key reference on this point.

The wiki page on CLOS is also very good.

So, maybe best method is to hold off with the theory and just practice with clojure multi-methods at some point... unless anyone wishes to chip in.

• I think this is language-specific enough to be off-topic, here at Computer Science. – David Richerby Aug 9 '19 at 12:16
• Idea - If you used one class to be a global container of all methods, (which would actually have to be static functions in this case), you could simulate multiple dispatch. You would always pass as the first parameter to any 'method' on this god object the first object concerned (in the single dispatch world this would be the class it belonged to), but then all the remaining parameters too could cause dispatch to different method bodies based on their type, via method overloading, so you'd have multiple dispatch, allbeit in very limited form (and barely OO any more perhaps, because static)... – mwal Aug 11 '19 at 23:36