I have gone through various articles, but I still do not know why instanceof should not be used. Kindly let me know your thoughts.
instanceof
I find a need to use instanceof hints at bad design. It's a sure sign that a big, complex switch-style construct will follow. Most other times I see it used, we should use polymorphism rather than instanceof. See the Strategy pattern. (relevant examples of use)
The only time I find I need to use it is when implementing equals(Object o).
equals(Object o)
1.4m articles
1.4m replys
5 comments
56.9k users