Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dynamic dispatch
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Single and multiple dispatch=== {{Main|Multiple dispatch}} The choice of which version of a method to call may be based either on a single object, or on a combination of objects. The former is called ''single dispatch'' and is directly supported by common object-oriented languages such as [[Smalltalk]], [[C++]], [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], [[Objective-C]], [[Swift (programming language)|Swift]], [[JavaScript]], and [[Python (programming language)|Python]]. In these and similar languages, one may call a method for [[Division (mathematics)|division]] with syntax that resembles <syntaxhighlight lang="python"> dividend.divide(divisor) # dividend / divisor </syntaxhighlight> where the parameters are optional. This is thought of as sending a message named {{mono|divide}} with parameter {{mono|divisor}} to {{mono|dividend}}. An implementation will be chosen based only on {{mono|dividend}}'s type (perhaps [[rational numbers|rational]], [[floating point]], [[matrix (mathematics)|matrix]]), disregarding the type or value of {{mono|divisor}}. By contrast, some languages dispatch methods or functions based on the combination of operands; in the division case, the types of the {{mono|dividend}} and {{mono|divisor}} together determine which {{mono|divide}} operation will be performed. This is known as ''multiple dispatch''. Examples of languages that support multiple dispatch are [[Common Lisp]], [[Dylan (programming language)|Dylan]], and [[Julia (programming language)|Julia]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)