HashMap.get() doesn't return the proper value, thanks to "hashCode()"
<p>I'm currently working on a TD game with a map editor. Now obviously, you can save and load these maps (or should be able to, at least).
Problem is: at some point I'm calling <code>.get()</code> on a <code>HashMap</code>. Unfortunately, the keys that should be the same (logic-wise) are not the same object (in terms of reference), and, according to my previous google research, overriding their <code>.equals</code> method isn't sufficient, since they still return different hashes with <code>.hashCode()</code> (I verified that, they DO return different hashes, while <code>.equals</code> does return true).<br>
(On a side note, that's rather confusing, since the javadoc of <code>HashMap.get(key)</code> only states that they have to be equal)</p>

<p>More specifically, the <code>HashMap</code> contains instances of a class <code>Path</code> of mine as keys, and should return the corresponding list of enemies (= value).</p>

<p>short version of <code>Path</code> (without getters etc.):</p>

<pre><code>public class Path
{
    private List&lt;Tile&gt; tiles = new ArrayList&lt;&gt;();
    @Override
    public boolean equals(Object obj) {
        //code comparing the two paths
    }
    @Override
    public int hashCode() {
        //what I still need to implement. ATM, it returns super.hashCode()
    }
}

public class Tile
{
    private int x;
    private int y;
    //constructor
    //overrides equals
    //getters &amp; some convenience methods
}
</code></pre>

<p>Now if two Paths are equal, I'd like them to return the same hash code, so that the <code>HashMap</code> returns the correct list of enemies. (I'll make sure not two identical paths can be added).</p>

<p>Now my question: </p>

<p>Do you suggest </p>

<ol>
<li>using some external library to generate a hash</li>
<li>that I write my own implementation of calculating a hash, or </li>
<li>something else</li>
</ol>

<p>?</p>

<p>Note that I'd prefer to avoid changing the <code>HashMap</code> to some other type of map, if that would even help solve the problem.</p>