regarding instanceof operator
posted 10 years ago
Here's a typical use of instanceof that's problematic.If this is an open-ended hierarchy, then as more classes extend A, you'll have to find the code like method f throughout your program and add more cases. A better solution in this case would be if there were a polymorphic method doF() that you could invoke:This doesn't mean that you should never use instanceof. There are places where it's unavoidable.