commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Blewitt <Alex.Blew...@ioshq.com>
Subject Re: JavaDoc of org.apache.commons.lang.builder.EqualsBuilder
Date Fri, 18 Oct 2002 23:56:42 GMT
>> o You don't point out that static and non-transient  fields should not
>> be used in the implementation of equals, which is required as per the
>> spec.
>
> I assume you mean transient. I reckon they don't harm if they are 
> checked
> (static final and transient, static would harm).

There is little point in checking static variables, since for all 
instances a1.sf and a2.sf (where sf is a static field of A) are 
identical. It would just result in an extra step in evaluating to 
'true'. Whilst it wouldn't do any harm, there would be no difference if 
they were ommitted, so it is probably not recommended to compare static.

The only time when this would come into play is if you were working 
with a static field that was changing during the execution of the 
equals method itself. In this case, is it not desirable that even with 
the changed static field the two objects return true? It would not be 
desirable for a.equals(b) to return true for all conditions except 
where a bizarre race condition briefly made a.equals(b) false, which 
would thereafter return true.

I did mean transient above though - got confused with my wording :-) I 
was half way through saying that the equals method should only check 
non-transient and non-static fields, and got my boolean logic mixed up 
:-)

> Alex.


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message