Re:Java Best Practices – String performance and Exact String...
by Sandman on Thursday July 14, 2011 @04:21PM
(#2764900)
Yes, you avoid NPE, but consider this piece of code:
Now, if for any reason the getBacteriaName() method failed and gave you a null instead of some string, the code will end up doing whatever it is you want it to do if the bacteria name is other than "botulinum". But this might not be what is really desired. The method failed and this should be taken into consideration. The string bacteria doesn't contain the name of some other bacteria, it's null. The problem here is that, under the circumstances, perhaps the code should have returned 'botulinum' but since the method failed, the program acts as if another bacteria name was fetched instead of throwing an exception. Just something to be careful about.
[ Parent
| on HN ]
There are no comments on this comment yet.