Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursive .equals method from call to super.equals
    primarykey
    data
    text
    <p><strong>Edit</strong></p> <p>I did a very poor job and gave incomplete information for anyone to determine the cause of my issue. The real issue was that I had a nested class in Animal which had its own .equals which called .equals on its outer type. (So calling .equals on animal called .equals on animal from the nested class's .equals).</p> <hr> <p>I have three classes in an inheritance tree. Let's say they're <code>Animal</code> --> <code>Dog&lt;Owner&gt;</code> --> <code>DogWithHumanOwner</code>.</p> <p>So DogWithHumanOwner is an implementation of the generic Dog that specifically has a Human for its owner. </p> <p>I have overriden Animal's and Dog's .equal methods. Dog's .equal method looks like this:</p> <pre><code>@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; [other stuff] return true; } </code></pre> <p>What I'm actually using though is a DogWithHumanOwner. It seems that when I try to compare the equality of two DogWithHumanOwner, the dogWithHumanOwnerinherits the equals method from <code>Dog&lt;Owner&gt;</code>, which calls super.equals, which is the dogWithHumanOwner's super classes' .equals method, which is the method it's in, and so it causes a recursive loop and a stackoverflow.</p> <p>(I don't need to compare any specific properties of the implementations of the <code>Dog&lt;Owner&gt;</code> class, because I do that in <code>Dog&lt;Owner&gt;</code> and owners need to have proper equals methods.) </p> <p>What is the best practice for writing a .equals method that avoid this issue? I'm drawing a blank. Should I just manually test the equality without calling super at all?</p> <p>Edit: I had to remove the BlackLabs, because it didn't make sense why I would want to do this with blackLabs.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload