Why Objective-C doesn't support method overloa

2019-01-14 17:45发布

问题:

Objective-C doesn't support methods overloading.
Why?
Is it doable but Apple decided not implement it? or it is not doable due the dynamic nature of Objective-C?

I have the impression that method overloading can be done on compiled languages (Java, C#) and can't be done on interpreted languages (Ruby, Python).
Holds some true?

回答1:

The distinction that's relevant here is not between compiled and interpreted languages, but between statically typed (Java, C#) and dynamically typed (Ruby, Python, Objective-C). In a dynamically typed language, type information is very often not known until runtime. At runtime, all objects are statically typed as id in Objective-C.

Additionally, a core idea in dynamically typed OO languages is that you should not care what type an object is as long as it responds to the messages you want to send. So overloading based on type would fly right in the face of that.