Re: java.lang.StackOverflowError

From: bm (behzad_mortazavi_at_hotmail.com)
Date: 10/27/03


Date: Mon, 27 Oct 2003 08:06:40 GMT

The minimal contract for overriding equals is
- insure that the test (o instanceof type-of-class-'this') is true before
proceeding
  otherwise you must return false. calling super.equals(o) directly won't be
sufficient
- if x.equals(y) is true then y.equals(x) must also return true
- if you override equals you must override hashcode as well
  a minimal but acceptable behaviour for hashcode is to return 1
  this method is used by containers to bin the inserted objects

after you have met the above conditions then you can call super.equals(o)

"Brad BARCLAY" <bbarclay@jsyncmanager.org> wrote in message
news:sn2nb.25848$7B1.3194@news04.bloor.is.net.cable.rogers.com...
> Asad Khan wrote:
> > I have the following method inside I class,
> >
> > public boolean equals(Object o) {
> > return (this.equals(o));
> > }
> >
> > but when i call this method by "foo.equals(bum)" where foo and bum are
some
> > objects, I get a java.lang.StackOverflowError??
> >
> > I kinda know why its happening; I think it calls the same equals method
and
> > keep going round and round. But, this is what I have to do, without
renaming
> > the method, so what's the way around it?
>
> You're getting this exception because you're recursing forever, with no
> end. This is not correct.
>
> Did you intend to call "super.equals(o)" instead?
>
> Brad BARCLAY
>
> --
> =-=-=-=-=-=-=-=-=
> From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
> The jSyncManager Project: http://www.jsyncmanager.org
> 
>