I am using Javascript with #pragma strict enabled, and I am also using Arrays for the dynamic push and pop feature set, because I need to be able to add and remove GameObjects from a list. However when Poping objects from the Array, I receive a downcasting warning since the Array objects are untyped.
How can I avoid this? Is there another object I can use that offers the push and pop functionality?
Arrays do not have dynamic push/pop’s, I think you’re confused. Arrays are fixed size. Maybe you’re talking about a List or ArrayList? There is a special datastructure called a stack which gives type safe pop/pushing, it’s called System.Collections.Generic.Stack
No, the JS Array class is dynamic and has push and pop. Note the difference between Array and array. However, Hippocode is right: don’t use it. Like, ever. Use List instead, then you don’t have to cast and it’s faster.
Yeah, if you want Push/Pop sort of behaviour, List or JS.Array is probably not the answer, but rather Queue or Stack (or Deque but that has to be downloaded/more work to get).
Queue works like a real life queue, where adding goes to the end, and removing pulls from the front, so the first one in is the first one out.
Stack works like a stack of objects (think Tower of Hanoi puzzle), this is last in, first out.
Ntero: List and Stack have pretty much identical performance when it comes to poping/pushing elements on the end, they are both implemented with an array as backing storage and the operation is O(1) complexity on both.