As far as I'm aware, Object was made different from * in order to make
it possible to program without thinking about the 'undefined' value,
which Object can't store. It banishes the 'undefined' value from the
part of the language that is compile-time-typed, because toher
compile-time-typed languages do not have both 'undefined' and 'null'.
 
The Object type requires downcasting because that's normal for all
compile-time-types. The * "type" doesn't require downcasting because it
isn't a compile-type-type at all. It is simply a notation that tells the
compiler "I really want this thing to have no compile time type" as
opposed to simply omitting the type annotation, which might mean "I
forgot to give this thing a compile-time-type".
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Derek Vadneau
Sent: Wednesday, May 23, 2007 9:07 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] star (*) data type vs. Object



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]
<mailto:[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
<mailto:flexcoders%40yahoogroups.com>  [mailto:
flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] On
        Behalf Of Derek Vadneau
        Sent: Wednesday, May 23, 2007 11:11 AM
        To: flexcoders@yahoogroups.com
<mailto: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]
<mailto:pfarland%40adobe.com> 
        
        <mailto:[EMAIL PROTECTED] <mailto:pfarland%40adobe.com> > >
wrote: 
        
        See:
        
        http://livedocs.adobe.com/flex/2/langref/specialTypes.html#*
<http://livedocs.adobe.com/flex/2/langref/specialTypes.html#*> 
        <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
<mailto:flexcoders%40yahoogroups.com> 
        <mailto:flexcoders% <mailto:flexcoders%25> 40yahoogroups.com
<http://40yahoogroups.com> > [mailto:
        flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
<mailto: flexcoders% <mailto:flexcoders%25> 40yahoogroups.com
<http://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