-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Error in book on page 334
PostPosted: Thu Mar 17, 2005 7:17 am 
Newbie

Joined: Thu Mar 17, 2005 7:06 am
Posts: 4
Hi,

I found an error in the book Hibernate in Action, on page 334.

On that page is a class UserId with an equals method which says on line 3:
Code:
if (o = null) return false;


This line will not compile!! It should of course be:
Code:
if (o == null) return false;


thanx,
Jan Hoeve


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 7:51 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thanks, added to Errata


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 12:53 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
Just a tip...

This is a fairly common bug, especially for people new to coding in Java or C++ (identical syntax). There are a couple of ways to catch it before it bites you.

1. Eclipse has an optional warning called "Possible accidental boolean assignment (e.g. if (a=b))". Turn this on! Other IDEs may have a similar feature -- if not, they should!

2. Swap the values so that the constant (in this case, "null") is on the left side. Since the constant cannot be assigned a value using "=", this will cause a compile error. This is a good practice to get used to.

Code:
if (null = o) {...} // compile error

if (null == o) {...} // no compile error


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.