You can't create a SmallInteger using new:
. You already have the number you want to print. It's already a SmallInteger. Just use it like such:
Transcript show: 0 printString
Вопрос
I've tried the code
|myNum|
myNum := SmallInteger new: 0.
Transcript show: (myNum printString).
, but Pharo crashes upon running this code.
Решение
You can't create a SmallInteger using new:
. You already have the number you want to print. It's already a SmallInteger. Just use it like such:
Transcript show: 0 printString
Другие советы
"SmallInteger new: 0" is not necessary since 0 is already a SmallInteger.
Besides, the #show: message of the Transcript object already sends #asString to its parameter, therefore it can receive any object.
So the correct code would be:
Transcript show: 0