I have a situation where I check for the instanceOf some classes for proceeding with my logic.
For eg.
if (obj instanceof X) { result = true; } But now this is being used in lot of places in my legacy code.
My problem is now this instanceOf should return true only if some global property variable is true.
I am looking for an alternative solution to replacing all these instanceOf checks as shown below:
if (GLOBALPROPERTY == true) { if (obj instanceof X) { result = true; } } Can I inject this check inside the class X itself so that, it will return false wherever I check for instanceOf this class.
result = obj instanceof Xinstead of theif.resultmay already betrueand he doesn't want it reset tofalse.ifandresult = true;?! Nevertheless, it was just a suggestion which could help the OP remove some (possible) extra code. Nothing else.