Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

instanceof considered harmful?

I am looking over some code that has heavy use of Java's instanceof operator. I will fight the temptation to go into details, since this is a general question. instanceof reminds me of of c++'s dynamic cast, and the advice I read about it, long ago, that if you think you need it, probably your model is off. Is this still the conventional wisdom? Does it apply to Java's instanceof?

like image 620
derekv Avatar asked Dec 04 '22 17:12

derekv


1 Answers

Yes, you are on the right track. While instanceof certainly has its uses, heavy use generally indicates that your class design is deficient.

like image 131
jtahlborn Avatar answered Dec 13 '22 06:12

jtahlborn