what is the syntax for casting an array of objects?
I'm getting a message:
[babble_patch.ck]:line(142): arguments type(s) do not match:
[babble_patch.ck]:line(142): ... for function
'PatchableObserver.attach_all(...)' ...
[babble_patch.ck]:line(142): ...(please check the argument types) The line in question in file babble_patch.ck:line(142):
PatchableObserver.attach_all(_handlers);
The declaration of _handlers in babble_patch.ck:line(76):
Handler @ _handlers[];
The declaration of the Handler class in babble_patch.ck:line(37):
class Handler extends PatchableObserver { ... }
And the declaration of attach_all in patchable_observer.ck:line(16):
fun static void attach_all(PatchableObserver ps[]) { ... }
What I *intend* is to pass an array of Handler objects to attach_all(). I can imagine that ChucK is concerned that Handler isn't the same as PatchableObject (don't laugh at me -- I've gotten used to Ruby's duck typing). But I can't figure out the syntax for casting an array of Handler[] as an array of PatchableObject[] to pass to attach_all(). Any ideas? [If need be I can make a smaller self-contained example. But my hope is that this is some easily answered question.] Thanks in advance, - Rob
Here's a self-contained example that demonstrates what I mean: class Obs {} class SubObs extends Obs {} fun void count(Obs elems[]) { <<< elems.size() >>>; } // works... [(new Obs), (new Obs)] @=> Obs @ x1[]; count(x1); // works but is really ugly.. [(new SubObs) $ Obs, (new SubObs) $ Obs] @=> Obs x2[]; count(x2); // Doesn't work: needs casting. but what's the syntax? [(new SubObs), (new SubObs)] @=> SubObs @ x3[]; count(x3);
participants (1)
-
Robert Poor