Closed p-fischer closed 7 years ago
This is an ugly hack for indexing included resources (#48). I've edit the class and you can try snapshot version to see if the patch solves your problem.
I've just released the patch to 3.2.2 🍻
There might be a misunderstanding. I want to have my own data class extending from Resource. In that data class I want to implement equals and hashcode in a way the equals contract is satisfied. That is impossible right now since ResourceIdentifier, which is a transitive superclass, already implements equals / hashcode. Since my data class introduces new attributes, thus extends the classes state, I cannot implement equals in a way the symmetry requirement can be satisfied.
I know that's quite subtle, but this testing library pointed me towards it.
There you can override equals
and hashCode
function and use your own implementation.
That's what I did. Still the symmetry of the equals
contract is not satisfied when I compare an instance of my own data class and an instance of ResourceIdentifier
. See my first comment.
I just wanted to point that out. But you can consider it low prio ;)
Umm... do you mean to make a.equals(b) == true
as long as a
and b
are both instance of ResourceIdentifier
with the same id
and type
?
I'd suggest the canEqual
approach from my link above. That would cause a.equals(b) == false
and b.equals(a) == false
if a is a superclass of b.
I read the article again. Generally, the newly implemented ResourceIdentifier
conforms to equality contract described there.
I want to write a valid equals method for my class extending from Resource taking into account its attributes. The issue is that its superclass ResourceIdentifier already overwrites
equals()
.One of the requirements for equals is symmetry. This is where I fail. Let's say my concrete instance is c an instance of ResourceIdentifier is s. If the both have equal type and id then
s.equals(c) == true
, howeverc.equals(s) == false
.There is a good read on that issue: http://www.artima.com/lejava/articles/equality.html
I see three options:
canEquals
approach as mentioned in the article to solve the problem.