似乎 GNU Smalltalk 中的 inheritsFrom: 方法对于作为参数发送给它的每个未定义的类名都返回 true。恕我直言,这可能会使程序非常难以调试。查看 Behavior 类中的代码,它看起来像这样:
inheritsFrom: aClass [
"Returns true if aClass is a superclass of the receiver"
<category: 'testing the class hierarchy'>
| sc |
aClass isNil ifTrue: [^true].
sc := self.
[sc := sc superclass.
sc isNil] whileFalse: [sc == aClass ifTrue: [^true]].
^false
]
aClass isNil ifTrue: [^true] 行是罪魁祸首,但我正在寻找一个理智的理由来说明它是以这种方式编码的。(顺便说一下,我是 Smalltalk 世界的新手,并且正在努力学习。)
谢谢。