继承情况下的构造函数(Squeak)

发布于 2024-08-13 18:39:59 字数 153 浏览 3 评论 0原文

我有一个类 A,B 继承自该类。继承包括一堆参数,在这两种情况下(无论我们创建 A 对象还是 B 对象),它们都应该初始化为一些默认值。我决定将初始化放入 A 的构造函数中,因为创建 B 应该首先创建 A。然而,这似乎并没有自动发生,而且我无法弄清楚如何手动调用超级构造函数。有人可以帮我吗?

I have a class A which B inherits from. The inheritance includes a bunch of parameters, and they should all be initialized to some default values in both cases (whether we create an A object or a B object). I decided to put the initialization into the constructor of A, since the creation of B should create an A first. However, this doesn't seem to be happening automatically, and I was unable to figure out how to call the super constructor manually. Can some one help me out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

寄居者 2024-08-20 18:39:59

您已经找到了解决方案,但这里还有一些注释可以帮助您更好地理解您的问题:

  • superself 类似,它们都代表消息的接收者。
  • self 开始在消息接收者中查找以下消息。
  • super 开始在定义实现方法的超类中查找以下消息。
  • selfsuper 不是消息,而是隐式变量,因此您无法在消息查找器中找到它们。

You already found the solution, but here are some more notes that might help you to understand your question better:

  • super is similar to self, they both represent the receiver of the message.
  • self starts the lookup of the following message in the receiver of the message.
  • super starts the lookup of the following message in the superclass where the implementing method is defined in.
  • self and super are not messages but implicit variables, therefor you cannot find them in the message finder.
夏の忆 2024-08-20 18:39:59

好吧,没关系……你用了“超级”这个词。
我想这解释了为什么在方法查找器中没有定义它的类列表。

OK never mind... You use the word super.
I guess that explains why there's no list of classes that define it in the method finder.

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