• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thou shalt never be equal to null?

 
Fabio Fonseca
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

Is it possible to check if something is equal to null? And receive a boolean answer? I'm pretty confused with this one, why I can have a value of null for an object and then right after can't I do boolean stuff on it?

please check what I did:

String userConfirmation = users.get(0).getConfirmationEmail();

---> It is an object that Hibernate gave me. It is a MySQL field which started with a null value. hibernate created this mysql field, therefore, its initial value is set (?) to null.

logger.info("confirmation email = " + userConfirmation);
logger.info("confirmation email = " + userConfirmation.equals(null));
logger.info("confirmation email = " + userConfirmation.equals(""));
logger.info("confirmation email = " + userConfirmation.equals("OK"));

----> What I received with the original field set to null:

1. mysql field equals null:

confirmation email = null
confirmation email = logic error

---> field set to empty string

2. mysql field equals empty string:

confirmation email =
confirmation email = false
confirmation email = true
confirmation email = false

---> field set to OK

3. mysql field equals OK:

confirmation email = OK
confirmation email = false
confirmation email = false
confirmation email = true


I know that I can update the field by hand, setting it all to empty string in mysql. But I want to understand why "equals(null)" doesn't works..

Thanks!

p.s. is this suited for this forum? have just read that "questions of any difficulty should be posted in the intermediate forum".. Moderators, please move my post if you think it is no suited for this forum.
thanks!
[ April 05, 2006: Message edited by: Fabio Fonseca ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can test to see if a reference is pointing to null with reference == null
 
Fabio Fonseca
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Lynn:
You can test to see if a reference is pointing to null with reference == null


Ermmm,

Keith, how do I actually do that?

thanks!
 
Henry Wong
author
Marshal
Pie
Posts: 21515
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Fabio Fonseca:


Ermmm,

Keith, how do I actually do that?

thanks!


Either ...



or...



will work.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic