The relevant parts are highlighted in bold in the Apple Objective-C documentation:
Method return and parameter types
The messaging procedure has access only to the implementation of the method through the selector, so it processes all methods with the same selector like this. It detects the return type of the method and the data types of its parameters, from the selector. Therefore, with the exception of sent messages for statically typed receivers, dynamic binding requires all implementations of the same named methods to have the same return type and the same parameter types. (Statically typed receivers are an exception to this rule because the compiler can learn about an implementation method from a class type.)
Although the same class methods and instance methods are represented by the same selector , they can have different types and return types.
I read this block again and again, but it seems I canโt get past what seems like a contradiction. First, he says that all implementations of the same named methods require the same return type and parameter types due to dynamic binding.
Since it applies to all methods with the same selector, does this mean that no matter how many different objects I have, if they all have an EatCake () method, then they will all use the same selector for EatCake ? If so, why should they have the same parameters and return type?
Then the next part says that although they are represented by the same selector, they can have different types of parameters and return types. So now I am completely confused, I thought it was just saying that it wasnโt.
I do not expect this to be a mistake, I expect I simply do not understand what the difference is between the two statements.
Can anyone clarify this for me?
Bigomega
source share