[jdom-interest] getText() returns null or ""
bob
bob at accurev.com
Wed Oct 4 09:35:21 PDT 2000
Hmmm..
At least in my usage of JDOM, I just like to use the text, whatever-it-may-be,
and not worry about testing against equals(""). I'm mostly doing transformations,
though, and not looking at an element and determining if it has text content
or not. I just use what's there (and "" is perfectly valid).
If it's truly a concern, performance-wise, an implementation could provide
a hasTextContext() method, checking against an internally stored null,
while getText() returns "" if !hasTextContent(). Encapusate the
test-against-null in the Element, while still allowing the empty
string to be returned for those of us who just expect a String
containing the characters (if any) in the element.
-bob
On Wed, 4 Oct 2000, Laurent Bihanic wrote:
>
> On the performance side, a test against null is much faster than an equals()
> on strings.
>
> Laurent
>
> Brett McLaughlin wrote:
> >
> > Folks-
> >
> > What's the deal with getText() returning null when it has no value?
> > That's what the docs say, and I guess that one just slipped by me (I've
> > been really busy lately ;-) ). In any case, that doesn't seem right -
> > wouldn't it be better to return ""? Is there any functional difference
> > between "" and null? It seems that returning null could cause
> > NullPointerExceptions, while "" always insures you can compare Strings.
> >
> > Thoughts? I'd like to suggest changing to returning the empty String
> > when there's no value.
> >
> > Thanks,
> > Brett
> > --
> > Brett McLaughlin, Enhydra Strategist
> > Lutris Technologies, Inc.
> > 1200 Pacific Avenue, Suite 300
> > Santa Cruz, CA 95060 USA
> > http://www.lutris.com
> > http://www.enhydra.org
> > _______________________________________________
> > To control your jdom-interest membership:
> > http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
>
More information about the jdom-interest
mailing list