I suspect that valueOf() returns *, not Object. You can assign something
of compile-time type * to something of any other type without casting.
However, when you assign something of compile-time type Object, you must
downcast it.

By the way, expressions like a[i] where a is an Array, or o.prop where o
is an Object, are considered to have compile-time type *. So you can
write, for example,

    var s:String = selectedItem.name;

rather than

    var s:String = String(selectedItem.name);

- Gordon


-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jens Halm
Sent: Wednesday, April 12, 2006 2:49 PM
To: Ted Patrick
Subject: Re: [flexcoders] programatically assigning an ArrayCollection
as the DataProvider bug...


> Geoffrey,

> This is a common misconception about return types. In the Flex
> docs, the type specified is the lowest subclass supported for the
> returned data. If the return type is Object, this can include Array,
> Boolean, String, Number, components, and most custom classes. 

> But alas that is not the issue here, Houston we have a bug!

Hm, I think the misconception is on your side. Of course the return
type Object allows almost anything at *runtime*, but the *compile*
time type is just Object and you have to cast to any other concrete
type. This is the case in ActionScript 2/3 and any other strongly
typed language I know (e.g. Java). In fact this is the reason why
Java 5 introduced Generics: You do not have to cast any more if you
take something out of a collection. But in AS we don't have Generics
(yet) so we have to cast. Without the need to cast in such a case the
whole type system would not make much sense.

Of course you have to differentiate between upcasting and downcasting!
Upcasting does not need an explicit cast:

var vo:ValueObject = new ValueObject();
var o:Object = vo; // upcast, casting is implicit!

But when downcasting you have to do an explicit cast:

var o:Object = dg.selectedItem;
var vo:ValueObject = ValueObject(o); // downcast, need to cast!


Don't know the issues related to the valueOf method. But... its return
type is Object too, so I think it's the other way around: The bug is
that the compiler does not complain when you use valueOf..


Jens




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



 





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to