cast operation in Squeak

Boris Gaertner Boris.Gaertner at gmx.net
Tue Mar 2 18:54:40 UTC 2004


From: "Kwiyi Woo" <kwiyi at hotmail.com> wrote:


> Hi,
> I want to cast a object to a certain class. How can I do cast operation in
> Squeak as in other programming language? For example, I can do something
> like in java:
>
> String i = (String)str;
>
> I couldn't figure out the syntac for it.
>
> Thanks
> Kwiyi
>
In some low-level languages, casting is a way to give
different interpretations to the contents of a given group
of contiguous memory cells. There is nothing like
casting in smalltalk, but there are conversion methods.
For objects of any class, you may wish to try
the method 'printString':

   (13 - 2) printString
will answer the string  '11'

 Conversions between collections are especially powerful.
Just try, for example:

 'The quick brown fox jumps over the lazy sleeping dog' asSet.

You get a set of all the characters in the string.
Try also the conversion methods 'asBag' 'asArray' 'asOrderedCollection'
'asSortedCollection'

Note that conversion always creates a new instance; you need
memory for both the given object and the converted object.

Hope this helps,
Boris





More information about the Squeak-dev mailing list