I have a colleague here in my project, who is deeply against the use of instanceof
operator, because it "generates a lot of overhead", what is the reason for that? Is it true?
Is there another way to check the type of the Object instead of using it?
Because I find it very useful in some occasions.
It does generate some overhead, combined with the subsequent casting. With recent version of Java the overhead has decreased. But anyway that's microoptimization - i.e. you should not worry about it in the general case.
The real argument against instanceof
is that in many cases there are better OOP ways to achieve the desired behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With