• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thou shalt never be equal to null?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Fabio Fonseca:


Ermmm,

Keith, how do I actually do that?

thanks!



Either ...



or...



will work.

Henry
reply
    Bookmark Topic Watch Topic
  • New Topic