为什么 Objective-C 不支持方法重载?

发布于 2024-10-07 18:58:31 字数 161 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身情人 2024-10-14 18:58:31

这里相关的区别不是编译语言和解释语言之间的区别,而是静态类型(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文