You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Felix Knecht <fe...@otego.com> on 2010/05/19 21:11:25 UTC

Is (@override) equals() here missing?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Can somebody explain, why this class [1] overrides hashCode() but not
equals()?

Thanks
Felix

[1]
http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/message/internal/InternalAbstractRequest.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkv0N90ACgkQ2lZVCB08qHFv2ACffIKroIbv8XaZXlgo4wWvUlFi
YRcAnA+NlHg+mvRpTAX7I+Vf/OBtBZlC
=JjTB
-----END PGP SIGNATURE-----

Re: Is (@override) equals() here missing?

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 5/19/10 9:34 PM, Felix Knecht wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Sorry, I was not clear:
>
> The method equals() is missing wheras the method hashCode() is
> implemented. Either both should be implemented (overridden) or none.
>
> So again, is it on purpose that the overriding equals method is missing?
>    
AFAIK, it's far worse to have equals() implemented and not hashcode() 
than the opposite. However, it should be a good thing to *always* have a 
equals() method and an haschcode() method together.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: Is (@override) equals() here missing?

Posted by Jeff MAURY <je...@jeffmaury.com>.
Both or none should be implemented.
Please not that Eclipse 3.5 offers a wizard to implement both in a single
test: chose the fields involved and both functions will be implemented. And
round trip is also supported.

Regards
Jeff MAURY

On Wed, May 19, 2010 at 9:34 PM, Felix Knecht <fe...@apache.org> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Sorry, I was not clear:
>
> The method equals() is missing wheras the method hashCode() is
> implemented. Either both should be implemented (overridden) or none.
>
> So again, is it on purpose that the overriding equals method is missing?
>
>
> > Well, @override is optional, and it's just a hint for the compiler, so
> > it's pretty common that the developper forgot to add it.
> >
> > I usually don't put an @override annotation to such metods (toString,
> > hashcode, equals...) but it's probably not a good idea.
> >
> > I would suggest that we ad it in any case.
> >
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.15 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkv0PTYACgkQ2lZVCB08qHHfXQCcDLFE6I1dhIo2TKqKeX+GSOmj
> cEEAoIPvvDv4MBitkvNXVy+7/4EZx7Q9
> =u1tc
> -----END PGP SIGNATURE-----
>



-- 
http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.lastfm.fr/listen/user/jeffmaury/personal

Re: Is (@override) equals() here missing?

Posted by Felix Knecht <fe...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sorry, I was not clear:

The method equals() is missing wheras the method hashCode() is
implemented. Either both should be implemented (overridden) or none.

So again, is it on purpose that the overriding equals method is missing?


> Well, @override is optional, and it's just a hint for the compiler, so
> it's pretty common that the developper forgot to add it.
> 
> I usually don't put an @override annotation to such metods (toString,
> hashcode, equals...) but it's probably not a good idea.
> 
> I would suggest that we ad it in any case.
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkv0PTYACgkQ2lZVCB08qHHfXQCcDLFE6I1dhIo2TKqKeX+GSOmj
cEEAoIPvvDv4MBitkvNXVy+7/4EZx7Q9
=u1tc
-----END PGP SIGNATURE-----

Re: Is (@override) equals() here missing?

Posted by Emmanuel Lecharny <el...@gmail.com>.
On 5/19/10 9:11 PM, Felix Knecht wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Can somebody explain, why this class [1] overrides hashCode() but not
> equals()?
>    

Well, @override is optional, and it's just a hint for the compiler, so 
it's pretty common that the developper forgot to add it.

I usually don't put an @override annotation to such metods (toString, 
hashcode, equals...) but it's probably not a good idea.

I would suggest that we ad it in any case.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: Is (@override) equals() here missing?

Posted by Felix Knecht <fe...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/19/10 21:11, Felix Knecht wrote:
> Can somebody explain, why this class [1] overrides hashCode() but not
> equals()?

All following have are lacking the same. Is this all on purpose or just
missed to implement?
http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/filter/AssertionNode.html
http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/filter/ExtensibleNode.html
http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/filter/ScopeNode.html
http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/filter/SubstringNode.html

> 
> Thanks
> Felix
> 
> [1]
> http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/message/internal/InternalAbstractRequest.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkv0OZwACgkQ2lZVCB08qHE9YwCg4jnz8giKMluqo/sROoUyVdWq
YnoAnRLbMt/BNYNs62hxISWN1Oxit5K1
=dXnW
-----END PGP SIGNATURE-----