[chuck-users] determining the type of an Object in code

Michael Heuer heuermh at gmail.com
Sun Sep 7 15:47:14 EDT 2008

Kassen wrote:
> 2008/9/5 Michael Heuer <heuermh at gmail.com>
>> For what it's worth, I have updated my List APIs to use resizeable
>> arrays and posted them to the forum at
>> http://electro-music.com/forum/viewtopic.php?t=21725
>> Each file contains some "unit tests" so you might look to those for
>> examples on how to use the list classes.
> Michael,
> Do I understand correctly that the top file, the one that deals purely with
> Object's, works but is mainly of interest from a academic perspective? I
> like what you are doing but it's not clear to me how we would get the
> results out at the other end without being able to tell anything about the
> type, beyond it being a "Object" and getting it's memory location.
> Is this purely meant as a abstract demonstration?
> Yours,
> Kas,

Hello Kas,

ChucK has a cast operator, so you should be able to cast the result of
List.get(int), Iterator.next(), or the object parameter in a
forEach(UnaryPredicate) to what you expect the Object to be.  This

ArrayList list;
Qux qux0;
Qux qux1;
Qux qux2;


list.get(0) $ Qux @=> Qux qux;

$ chuck --silent list_of_qux.ck
42 :(int)


More information about the chuck-users mailing list