Open danielpaz6 opened 4 years ago
Yes, dig for the details, but I’m pretty sure it checks if the object has a equals() method and allow what you describe, but the problem you’re going to have is that your tuple is just an array, and adding the equals method on each instance... right, not good. Best would be to have a type of yours instead of just a plain array, that way you have the right structure to consider them equal.
Hi,
So I have a pretty simple example to demonstrate my problem:
So in this example, I have a Map that uses tuple of Shapes as a key. And it returns false since when using
[shape1, shape2]
twice, it creates two different arrays in terms of address so thehas
method probably makes a shallow comparison between them, and as a result, returns false.I thought maybe I could override
has
method to fits my needs? to shallow comparison Shape1 and Shape2 instead of the whole array.Could it be done via collections package?