I'm having thousands of files coming in each hour, and I have to parse it.. and do some usual stuff.
Now the problem is, to carry out some logic I am putting on some checks using "instanceof" operator in my code, now the architect says "we should be using a boolean under some conditions... its not wise to use "instanceof" as they will make the application expensive...
Is it so ? should I go with the boolean approach... if this is the case... why does java even has that operator..... I love java... I want to use everything..
" My heart says yes... my architect says no " - well give me some reason which he wont give...
Time is what we want the most, but what we use the worst. -- William Penn
If you have two alternatives, it's possible to compare them. If you have only one, there's no point asking the question. This "using a boolean" idea would need to have a concrete implementation before you could consider it, otherwise it's just hand-waving.
But before even asking the question, you should profile the application and see if the line of code containing "instanceof" is using a significant percentage of CPU or elapsed time or whatever you're concerned with. I'm willing to bet that it doesn't, and that your architect is prematurely optimizing.
Yay!.. thanks.. and yes "expensive" was referring to performance (CPU time) - as there are I/O operations involved and for a very huge number of files...anyways.. I'll extend your bet! I will try to prove my point again to him..) till I come running to coderanch .. will keep you posted
Your compiled Java code has loads of instanceof operations, even though you didnt put them in. EVERY reference assignment that is at all in doubt is checked. Furthermore, the designers have put a big effort into making instanceof very efficient.