Object subclass: Node [
|value|
new [
Transcript show: 'Test'.
value := 6.
]
getValue [
^value.
]
set:sth [
value := sth.
]
]
|data|
data := Node new.
Transcript show: (data getValue) printString ; cr. "nil"
data set:5.
Transcript show: (data getValue) printString. "5"
问题是一个new
方法永远不会被调用,所以我不能设置值或调用初始化函数。此外,在这样的事情之后:
object := Node new. "Not called"
object new. "Here is called"
该方法被调用。如何解决?