Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why hashCode and equals methods are not working when a List implemented object stores its own object as a element in the list [closed]

Why don't hashCode() and equals() work when a List implemented object stores its own object as a element?

like image 704
Anshul Mohil Avatar asked Jan 30 '26 10:01

Anshul Mohil


1 Answers

A List bases its equals relation on the contents of the list. If one of the members is the list itself, infinite recursion ensues. The same problem occurs with hashCode.

like image 89
Marko Topolnik Avatar answered Feb 01 '26 01:02

Marko Topolnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!