Question

I've tried the code

|myNum|
myNum := SmallInteger new: 0.
Transcript show: (myNum printString).

, but Pharo crashes upon running this code.

Était-ce utile?

La solution

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

Autres conseils

"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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top