Search code examples
javaobjective-cbindingmethodsmessage

Is calling a method in Java the same as sending a message to an object in Objective-C?


The Java's syntax for calling a method is the following:

object.methodName(...)

In Objective-C, the syntax for sending a message to an object is the following:

[object methodName:...]

Better, suppose you have an interface in Java (say Aj) and an object which implements this interface (say Bj). Suppose also to have a protocol in Objective-C (say Ac) and a class which implements that protocol (say Bc).

Java:

Aj object = new Bj();
Aj.method();

Objective-C:

Ac* object = [[Bc alloc] init];
[Ac method];

Obviously it is different. But what I think is: in both cases the binding of the method to the right object is done dynamically, then I think that also Java uses messages and chooses the right method at runtime. Is it correct?

Can I affirm that also Java uses the "messages' mechanism" for calling object's methods?


Solution

  • According to this article, it looks like the Java VM has a similar "message" mechanism to Obj-C: http://www.informit.com/articles/article.aspx?p=1571983

    Just breezed through it though, could be wrong.