Domanda

I've tried the code

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

, but Pharo crashes upon running this code.

È stato utile?

Soluzione

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

Altri suggerimenti

"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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top