以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 软件工程论坛 』   (http://bbs.xml.org.cn/list.asp?boardid=48)
----  downcast 和 typecast的区别  (http://bbs.xml.org.cn/dispbbs.asp?boardid=48&rootid=&id=35409)


--  作者:pennyliang
--  发布时间:7/9/2006 7:14:00 PM

--  downcast 和 typecast的区别
来看例子
int i=(int) d;
此时 i 和 d 是完全不同的对象,这就是typecast

Account acc = (Account) accounts.elementAt (i);
此时acc和数组中i位置的对象是同一个对象
accounts.elementAt (i)所指的对象是acc或者acc的子类,在这种情况下,downcast是正确的,否则抛出转型异常。

综上,
Students are often confused about downcasts, and think that some kind of conversion is taking place. This is not true. The downcast is simply a test; no change to the object occurs.


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms