0 Replies Latest reply on May 26, 2009 12:25 PM by BorekB

    Little cheat to document the type of ArrayCollection's items

    BorekB Level 1

      I though I would share how I document the actual type that will be stored in an ArrayCollection.


      If you see a line like this:


      public var items : ArrayCollection;


      you have no clue what type is actually stored in the array. It can be string, integer, custom objects, whatever. What I used to do is this:


      public var items : ArrayCollection /* of Customer */;


      which doesn't help the compiler but it certainly does help to the maintainer of the application (often, yourself!). The problem is that if you later changed the name of the class (say from Customer to Client), this "documentation" will get out of date. A few moments ago, it just occured to me that I could possibly use this:


      public var items : ArrayCollection; typeof(Customer);


      It compiles fine and although the typeof(...) statement doesn't do anything useful, it pretty well documents what type of objects are stored in the array.


      I think I'm going to use it in my projects. Obviously, proper generics support in AVM would be nicer but in the meantime, I think it's better than nothing.