Why cast after an instanceOf?

前端 未结 11 1887
情歌与酒
情歌与酒 2020-11-30 11:05

In the example below (from my coursepack), we want to give to the Square instance c1 the reference of some other object p1, but only i

11条回答
  •  心在旅途
    2020-11-30 11:29

    There's a difference between measuring if some object will fit in a box, and actually putting it in the box. instanceof is the former, and casting is the latter.

提交回复
热议问题