The problem is that AS3 is trying to catch inheritance issues (which *does*
go a bit against the dynamic typing grain, but that's kind of the point of
AS3). So, String is an Object but Object isn't necessarily a String (which
is why the compiler requires a typecast). So, a dynamic type would be
convenient (in that you save the keystrokes of the typecast) but you'd also
lose the type information (so you couldn't do something like
myObject.myMethod().anotherMethod() and have the IDE help you out or the
compiler verify it).

You could always disable strict type checking in your project properties...
that should eliminate the issue all together (I believe the end result is an
implicit cast to whatever the type is of the desintation or l-value is).

Troy.


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

  It's not about getting around compile-time checking, which is what you'd
be doing with Object anyhow, I think. Sometimes you really need to
dynamically type. In that case, why is Object better than *? Is it for
checking null vs. undefined in some cases or is there more to it?



On 5/23/07, Peter Farland <[EMAIL PROTECTED]> wrote:
>
>
> "...but you can't actually type the return variable to anything except
> Object or nothing."
>
> Not true. In your example, you simply need to cast to the correct type,
> i.e. String:
>
> var s:String = go() as String;
>
> I don't think using * to get around compile-time type checking is a good
> idea. You really should be casting values when assigning them from
> generic types as a best practice.
>
> Pete
>
> ________________________________
>
> From: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com> 
[mailto:flexcoders@yahoogroups.com<flexcoders%40yahoogroups.com>]
> On
> Behalf Of Derek Vadneau
> Sent: Wednesday, May 23, 2007 11:11 AM
> To: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
> Subject: Re: [flexcoders] star (*) data type vs. Object
>
>
> "* 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] <pfarland%40adobe.com>
> <mailto:[EMAIL PROTECTED] <pfarland%40adobe.com>> > wrote:
>
> See:
>
> http://livedocs.adobe.com/flex/2/langref/specialTypes.html#*
> <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: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
> <mailto:flexcoders% <flexcoders%25>40yahoogroups.com> [mailto:
> flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com> 
<mailto:flexcoders%<flexcoders%25>
> 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
>
>


--

Derek Vadneau

Reply via email to