By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,554 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,554 IT Pros & Developers. It's quick & easy.

java.lang.StackOverflowError

P: n/a
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?

Thanks.


Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
why do you have to do this?

"Asad Khan" <uo**********@yahoo.com> wrote in message
news:3e*******************@news01.bloor.is.net.cab le.rogers.com...
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?

Thanks.

Jul 17 '05 #2

P: n/a
well that helps!

i do because just because. (trying something out).
"Phil..." <ry***@ieee.org> wrote in message
news:Ix%mb.27905$275.49290@attbi_s53...
why do you have to do this?

"Asad Khan" <uo**********@yahoo.com> wrote in message
news:3e*******************@news01.bloor.is.net.cab le.rogers.com...
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?

Thanks.


Jul 17 '05 #3

P: n/a
SPG
OK, This will definitely not work.

What you are doing is overriding the equals() method in the super class,
then recalling it, thus entering an infinite loop causing the stack flow
exception.

Only override equals() if you want to compare your oblject to another in a
different way, IE: by an ID or its name etc..

public boolean equals(Object o){
return this.getName().equals(o);
}

or if you are intent on overriding the equals method and then re-delgating
back tot he super class try this:

public boolean equals(Object o){
return super.equals(o);
}

HTH

Steve
"Asad Khan" <uo**********@yahoo.com> wrote in message
news:3e*******************@news01.bloor.is.net.cab le.rogers.com...
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?

Thanks.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.