Hi,
>>I've always been a bit confused about a call to return ""...it should
>return a an empty string, but I kept >encountering nulls, so now I always
>use return new String("") instead.
>
>No, you should be fine doing a simple return( "" );
>
>I sometimes use the tenary operator as follows:
>
>this.name = name == null ? "" : name;
>
>as an inline equivalent of what your method does. In fact this is only one
>of the few cases where I use the tenary operator.
>
>It's debateable which is better/more readable/etc...
Two things. First, I agree that you should just return "" and not return
new String("");. In my opinion, why are you creating a NEW object if your
simply returning an empty string? IT seems to me a waste of memory. Does
the garbage collector know right away that this NEW object is empty? I
think, when a value is set the object should be created. I think its bad
design to return a NEW object unless that is the intention, and in my time,
I haven't seen that to be the case.
Secondly, while I like the ability to put in a single line a return like
what you did, I think it makes code harder to read. Thats not to say a good
developer shouldn't be able to understand that, but the majority of code I
have seen and worked with do not use this method. Its more readable and
easier to understand, especially for those that dont understand the code
well yet (such as those that are newbies in a company and need to learn the
current code-base and dont fully grasp the language yet). I do believe it
produces the same result when compiled, so for the sake of saving one or
two lines of code, I dont see it as the best choice. Really, its a matter
of opinion.
Kevin Duffey
Software Engineer
[EMAIL PROTECTED]
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html