The idea of strongly typed arrays is to catch errors at compile time
that otherwise might crop up at runtime.

Untyped:
------------
var arr:Array=[];

arr.push(new Button());
arr.push(123);

for (var i:int=0;i<arr.length;i++)
{
   var b:Button=arr[i];   // Works fine when i=0. Runtime error when i=1;
}

Typed
--------
var arr:Array.<Button>=[];

arr.push(new Button());
arr.push(123); // Won't compile, as the compiler knows that things in
arr must be Button

var b:Button=arr[0];
var c:Number=arr[1]; // Won't compile, as the compiler knows that
things in arr must be Button

---------

See? In short, typing the array means that (as far as it is possible
to do so) the compiler will ensure that the items you put into the
array are of the correct type, and because it knows the type of
objects stored in the array it will do strict type checking when
retrieving values from the array.

This is the same as generics in Java, C# or haXe and as templates in C++.

(Why on earth the ECMA team decided on the odd Collection.<type>
syntax rather than the standard Collection<type> syntax, I have no
idea. The extra dot feels completely superfluous.)

Hope that makes sense,
   Ian



On Wed, Sep 24, 2008 at 8:44 PM, Mendelsohn, Michael
<[EMAIL PROTECTED]> wrote:
> Not sure what strongly typed arrays are.  What are the advantages?
>
>
>
>
>> OOooh - strongly typed arrays!  Awesome!  I've been waiting for that
> for a long time!  Sweet.
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to