Questions tagged [method-dispatch]

For questions and answers related to dynamically calling object methods at runtime

Overview

Method dispatch is a fundamental concept in many programming languages that allows objects to dynamically call methods at runtime.

In Python, the getattr function provides a way to retrieve attributes and methods from an object by name, and dynamically invoke them using the parentheses operator.

Similarly, in Ruby, the send method allows objects to invoke methods with the same name as a given symbol.

Other programming languages, such as Java and C++, use a similar mechanism called "virtual method dispatch", which dynamically selects the correct implementation of a method based on the type of the object at runtime.

Method dispatch is a key aspect of object-oriented programming, enabling polymorphism and dynamic behavior in complex software systems.

See also

Wikipedia

38 questions
1
vote
0 answers

Java resolving overloaded method invocation when value null is used as argument

Why is Java executing method(char[] a) for method(null) if there is also method(Object a) instead of generating ambiguous method error? When trying to build a string using the static method String.valueOf()... i face this situation. Please, see the…
Victor
  • 3,841
  • 2
  • 37
  • 63
1
vote
0 answers

How does Ruby dispatch methods when super is called?

I'm doing some research into the internals of how methods are called in some object-oriented languages for a hobby project. I have found information about normal dispatch is fairly easy to come by, but calling the "supermethod" of a class's method…
Victor
  • 121
  • 5
1
vote
2 answers

Find which method WCF will dispatch a RESTful request to

Suppose I implement a WCF REST service with the following contract. [ServiceContract] interface INotesService { [OperationContract] [WebInvoke(Method = "GET", UriTemplate = "notes/{id}")] Note GetNote(string id); …
MvdD
  • 22,082
  • 8
  • 65
  • 93
0
votes
1 answer

Itemclick event in datagrid

The problem can be summarized as when clicking an item in datagrid, the text area shows the value of the item, but here the compoents are separate and hence events need to be dispatched. My mxml component file :
user120118
  • 65
  • 3
  • 8
  • 18
0
votes
1 answer

How to add a new specializer to cl-defmethod apply to multiple major-modes?

How can I extend a cl-defmethod to match on multiple major-modes? There is a little documentation in cl-generic, but I don't understand what is going on with the generalizer macros. As an example, (cl-defgeneric my-gen-fun (arg) (message "%S"…
Rorschach
  • 31,301
  • 5
  • 78
  • 129
0
votes
0 answers

Best/most performant way to add function methods within a different function in Julia

In my problem, I have a function, say optim, that takes as one of its arguments another function, say objfunc, along with some other arguments: optim(objfunc, args...) I wish to call this function within another function, let's call it run_expt,…
kiliantics
  • 1,148
  • 1
  • 8
  • 11
0
votes
0 answers

What would make a virtual call faster than regular one

I know virtual calls are generally longer than regular calls, mostly because you have to check the VTable before any virtual call. However, lately I had a case (on a huge project) where removing the word "virtual" from a method actually slowed down…
V.Leymarie
  • 2,708
  • 2
  • 11
  • 18
-1
votes
1 answer

Swift which method dispatch is used?

Which dispatch method is used in the following example. I read through some articles and seems to be any extensions methods are static. But is it calls witness table. My assumptions is that static dispatch uses only single declarations of methods,…
1 2
3