为什么 Objective-C 不支持方法重载?
Objective-C 不支持方法重载。
为什么?
这是可行的,但苹果决定不实施吗?或者由于 Objective-C 的动态特性而无法实现?
我的印象是方法重载可以在编译语言(Java、C#)上完成,而不能在解释语言(Ruby、Python)上完成。
有一些真实的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里相关的区别不是编译语言和解释语言之间的区别,而是静态类型(Java、C#)和动态类型(Ruby、Python、Objective-C)之间的区别。在动态类型语言中,类型信息通常要到运行时才知道。在运行时,所有对象都静态类型化为 Objective-C 中的
id
。此外,动态类型面向对象语言的核心思想是,您不应该关心对象是什么类型,只要它响应您想要发送的消息即可。因此,基于类型的重载将与此背道而驰。
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.