469,267 Members | 952 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

java.lang.StackOverflowError

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
3 30590
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
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
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.

Similar topics

reply views Thread by James Hong | last post: by
reply views Thread by Ravi Tallury | last post: by
1 post views Thread by tarun | last post: by
2 posts views Thread by Dragonxpert | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.