Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.equals and request.getparameter

 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to know what would be the correct way of doing something like this



since .getPArameter doesnt put "" if the parameter is not found
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh Khan wrote:

since .getPArameter doesnt put "" if the parameter is not found


Yes. if parameter returns null then you will be end up with an exception.
so you can do this since equals method dont throw exception if the argument is null, instead it returns false.
or

I always use later idiom. because some times you need to invoke a method on string_
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but it should be
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh Khan wrote:Thanks but it should be

Seetharaman's version is fine. It's a very common idiom. The point of using if(string_ != null && !string_.equals("")) is that the expression "short-circuits". If the first part is false it doesn't bother calculating the second part. So you can be sure that if it reaches the second part string_ is definitely not null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic