[合集] 问一下这个cast在java里是怎么work的# Java - 爪哇娇娃
I*e
1 楼
☆─────────────────────────────────────☆
bruklyn (我爱布鲁克林) 于 (Fri Aug 10 03:13:39 2007) 提到:
public Derived Clone()
{
Derived d = (Derived) super.clone();
... set other fields in d
return d;
}
这里我理解没错的话super.clone()应该返回一个Base class type的object
怎么可能cast成derived class type,而且还能set field呢?
有没有高人能解释一下?
谢谢!
☆─────────────────────────────────────☆
magicfat (魔法胖子) 于 (Fri Aug 10 12:16:54 2007) 提到:
Are you sure it works for you? I got ClassCastException.
I can't see how it
bruklyn (我爱布鲁克林) 于 (Fri Aug 10 03:13:39 2007) 提到:
public Derived Clone()
{
Derived d = (Derived) super.clone();
... set other fields in d
return d;
}
这里我理解没错的话super.clone()应该返回一个Base class type的object
怎么可能cast成derived class type,而且还能set field呢?
有没有高人能解释一下?
谢谢!
☆─────────────────────────────────────☆
magicfat (魔法胖子) 于 (Fri Aug 10 12:16:54 2007) 提到:
Are you sure it works for you? I got ClassCastException.
I can't see how it