D
Digital Puer
I've read that using instanceof to downcast is considered a
sign of poor OO design. What are some reasonable scenarios
where you would definitely need to use instanceof?
I can think of a few:
1. In old Java 1.0 GUI code, you see a lot of instanceof in
the action() method.
2. If you're using a ClassLoader and load a class, you need
use instanceof to see what kind of class you got.
3. If you're putting a mix of types into say, a vector, and
when you pull them out, you need to figure out which is which.
sign of poor OO design. What are some reasonable scenarios
where you would definitely need to use instanceof?
I can think of a few:
1. In old Java 1.0 GUI code, you see a lot of instanceof in
the action() method.
2. If you're using a ClassLoader and load a class, you need
use instanceof to see what kind of class you got.
3. If you're putting a mix of types into say, a vector, and
when you pull them out, you need to figure out which is which.