开发者

Flex DataType Conversion

I have a very simple question regarding the type conversion in flex.

What is th开发者_JAVA技巧e difference between these two conversions.

1) var arrCol:ArrayCollection = new ArrayCollection(event.result.dataset.table);

2) var arrCol:ArrayCollection = event.result.dataset.table as ArrayCollection;

I have seen that the second conversion works better(more number of times) than the first one.


I think the term "conversion" isn't correct. In your code snippets there are present instantiating and casting.

The case 1) is instantiating (creating of new instance of class). To determine it take a look at new keyword. And the parameter is Array instance according to ArrayCollection's constructor documentation.

The case 2) is casting. In your case event.result.dataset.table should be an ArrayCollection. Otherwise the value of arrCol will be null. Another form of casting is:

var arrCol:ArrayCollection = ArrayCollection (event.result.dataset.table);

In this case if event.result.dataset.table isn't an ArrayCollection there will be runtime exception. Because of Array and ArrayCollection are incompatible types and can't cast them to each other.


event.result.dataset.table as ArrayCollection is more readable and faster to write. But I remember some situation where flex threw an error when object was converted this way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜