Issues creating instance of SmallInteger

Tom Phoenix rootbeer at redcat.com
Fri May 12 16:19:09 UTC 2006


On 5/12/06, Michel Calonne <Michel.Calonne at etu.univ-savoie.fr> wrote:

> I've got a problem creating objects via this sample of code:
> (Smalltalk at: #AClassName) new
> The problem is that, when trying to create an instance of SmallInteger,
> it raises an error :
> "SmallIntegers can only be created by performing arithmetic"...
> If somebody can tell me why it isn't possible to create a SmallInteger
> like this, and give me a way to do it, I'd appreciate...
> And are there other classes behaving the same way? So that I can
> take them in account in my code.

SmallIntegers are implemented in a different way than most ordinary
objects, so they don't use #new. Some other classes don't create
instances with #new; Boolean is one.

As an alternative to #new, you could try #initializedInstance, which
should work with nearly any class.

Hope this helps!

--Tom Phoenix



More information about the Squeak-dev mailing list