When should and shouldn't instanceof be used?

后端 未结 5 637
情书的邮戳
情书的邮戳 2020-12-09 10:50

I have gone through various articles, but I still do not know why instanceof should not be used. Kindly let me know your thoughts.

5条回答
  •  借酒劲吻你
    2020-12-09 11:21

    When you know the object being passed then you need not use it. If there is any ambiguity involved (like two classes implementing the same interface) then it is advised to use instanceof before proceeding further.

提交回复
热议问题