Cedric Beust wrote:
>
> > From: A mailing list for Enterprise JavaBeans development
> > [mailto:[EMAIL PROTECTED]]On Behalf Of Satyabrata Dash
>
> > Again we override equals() method to find out whether the primary key is same
> > or not.
As with hashCode(), you don't *have* to override equals() either. All
java classes have an equals method inherited from java.lang.Object. The
reason you *should* override equals is because Object.equals() compares
the instance references for equality, and not the contents of the
instances. When you have objects that model entities or when you have
primary keys, you want the equality to depend on the contents or
attributes of the instance, and not the object references.
> A good Java rule of thumb is: "if you need to implement either equals() or
> hashCode() in your class, then you should implement both".
And most of the time, you'll probably want to override equals(), so that
equals will test the contents of the objects.
K Mukhar
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".