当前位置:网站首页>[interview question] the difference between instancof and getclass()

[interview question] the difference between instancof and getclass()

2022-06-25 00:03:00 Juzijun who doesn't want to sleep

I've been learning about 《Effective Java》 Mentioned in eques When the method is limited , There is talk about igetClass() Can replace nstanceof To determine whether it is the same subclass . So I learned the difference between the two .

To put it simply , The difference is , It is also used to judge whether the subclass and the parent class are equal , Subclass instanceof Parent class by true
Subclass .getClass() == Parent class .getClass() by false.

Because of this simple difference , In the implementation of subclasses equals() When the method is used , Pay more attention to

原网站

版权声明
本文为[Juzijun who doesn't want to sleep]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241921348177.html