当前位置: 代码迷 >> Java相关 >> [求助]有关instance
  详细解决方案

[求助]有关instance

热度:308   发布时间:2005-01-29 12:57:00.0
[求助]有关instance
已知instanceof运算符的作用是决定一个实例在运行时刻的类型。
现有类shape,他的子类是soshape。
有如下代码:
soshape obj,
if( obj instanceof soshape )
{
    soshape object = ( soshape )obj;
    ……//do something with object;
}
这里表达式:obj instanceof soshape 是真值,为何后边的语句块中还用强制类型转换( soshape )obj,这是不是多此一举啊?
想听听众高手们的意见,由于小弟对instanceof运算符还不是很了解,如果高手们能对我做一下关于 instanceof 的解释,那就再好不过。
搜索更多相关的解决方案: instance  

----------------解决方案--------------------------------------------------------
  相关解决方案