good post and i agree, dictionaries and arrays should return *

On 5/23/07, Derek Vadneau <[EMAIL PROTECTED]> wrote:

  "* is just like Object"

I couldn't disagree more.

I really dislike that Object is referred to in the docs about *. There is
an implication there that they are similar when they really aren't.

This is a sore spot for me everytime I use Array.pop() and Array.shift()
in the Flash IDE. Both of those functions have their returns typed as
Object. Why? Someone thought it was a good idea because you can have any
type returned ... Well, no. Yes, you can have any type returned at runtime,
but you can't actually type the return variable to anything except Object or
nothing.

For example, the Array.as file in the Flash 8 Classes folder defines:
function shift():Object;

If you try to do this you will get a compiler error:

var arr:Array = new Array(3);
var n:Number = arr.shift(); << compiler error


The same holds true in AS3. For example:

function go():Object
{
return 'something';
}

Everything's valid here. Setting the return type to Object allows me to
return any type that subclasses Object, which is everything.

var s:String = go(); << compiler error

"Implicit coercion of a value with static type Object to a possibly
unrelated type String."

The compiler doesn't swing that way!

So Object and * are NOT interchangeable. And the difference isn't subtle.

Use Object when you want to actually use generic objects and * when you
want to dynamically-type something.



On 5/18/07, Peter Farland < [EMAIL PROTECTED]> wrote:
>
>   See:
>
> http://livedocs.adobe.com/flex/2/langref/specialTypes.html#*
>
> The type * is just like Object but it can also store values that are
> undefined. Object can only store null.
>
> It's useful to determine whether a dynamic property actually exists on a
> type and just happens to be null, or whether it literally is not defined
> on that type.
>
> ________________________________
>
> From: [email protected] <flexcoders%40yahoogroups.com> 
[mailto:[email protected]<flexcoders%40yahoogroups.com>]
> On
> Behalf Of Adam Pasztory
> Sent: Friday, May 18, 2007 2:42 PM
> To: flexcoders
> Subject: [flexcoders] star (*) data type vs. Object
>
> Can anyone tell me what the difference is between setting a generic
> variable's data type to Object and setting it to *. Are they
> equivalent?
>
> I tried to search for the answer, but it's hard to do a search for *. :)
>
> thanks,
> Adam
>
>


--

Derek Vadneau



--
j:pn
http://www.lennel.org

Reply via email to