继承情况下的构造函数(Squeak)
我有一个类 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您已经找到了解决方案,但这里还有一些注释可以帮助您更好地理解您的问题:
super
与self
类似,它们都代表消息的接收者。self
开始在消息接收者中查找以下消息。super
开始在定义实现方法的超类中查找以下消息。self
和super
不是消息,而是隐式变量,因此您无法在消息查找器中找到它们。You already found the solution, but here are some more notes that might help you to understand your question better:
super
is similar toself
, 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
andsuper
are not messages but implicit variables, therefor you cannot find them in the message finder.好吧,没关系……你用了“超级”这个词。
我想这解释了为什么在方法查找器中没有定义它的类列表。
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.