• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Beginnerquestion about if (personName==null || personName.equals(""))
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beginnerquestion about if (personName==null || personName.equals(""))


  • Subject: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • From: Ian Joyner <email@hidden>
  • Date: Mon, 10 Sep 2007 10:58:08 +1000

On 07/09/2007, at 7:44 PM, Rainer User wrote:


Hi Folks, i am new at the webobjects-dev maillist and new to webobjects too.

I am reading the white printed book "Webobjects 5, Web Applications", from Apple, it was included in the Webobjects Package of my Webobject-Box.

On Page 84 i found an example where a funktion trys to detect if a variable named "personName" [type of it is "String"] is empty or not.

The substantial Code says:

if (personName==null || personName.equals(""))
{
	return(true);
}
else
{
	return(false);
}

You should never set a boolean flag like this... well yes it works but is poor style. Better:


return personName == null || personName.equals ("")

booleans can be used in expressions, just like numbers.

In my opinion it would be the same if i write only:

if (personName==null)

No, personName == null and personName.equals ("") are two different tests. personName != null is a precondition (see Chuck's comments on DbC) for personName.equals ("") to work.


{
	return(true);
}
else
{
	return(false);
}

Where is my misunderstanding?
Why i have to use personName.equals("") +and+ personName==null to detect if personName is empty or not?



Maybe someone can help me ore give me a hint?



Thanks from Germany,

Thomas


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Beginnerquestion about if (personName==null || personName.equals("")) (From: Rainer User <email@hidden>)

  • Prev by Date: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • Next by Date: running objective - c script as fastcgi ?
  • Previous by thread: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • Next by thread: TextExpander
  • Index(es):
    • Date
    • Thread