`

数组类型某些情况不能直接强转

阅读更多
例如,

class  Son, class Father.

Son extends Father

Son son, Father father

Object[] oa= new Object[]{son};

(Father[])fs=(Father[])oa; //强转失败,classCastException.



Son[] ss =new Son[]{son};

(Father[])fs=(Father[])ss; //成功。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics