Dynamic binding == late binding in Java or not?

2019-04-27 18:43发布

问题:

In different sources i've read different things on the topic. For example Wikipedia says:

Late binding is often confused with dynamic dispatch, but there are significant differences.

But a couple lines later

it is popular to use the term late binding in Java programming as a synonym for dynamic dispatch. Specifically, this refers to Java's single dispatch mechanism used with virtual methods.

So where's the truth and what are this "significant differences"?

回答1:

Late binding and dynamic single dispatch are, for all intents and purposes, the same. In dynamic single dispatch, the value or identity of a single object determines which code is invoked at runtime, and that's what happens in Java.

The term dynamic dispatch in general is most often used to imply dynamic multiple dispatch, which is where the runtime method is chosen at runtime based on the identities or values of more than one object, which is a language feature in CLOS and Smalltalk, but not in Java or C++.