m
Yes.
c
Okay. That makes sense. Thanks.
But I’m wondering does it make sense to implement
equals()
for a non-
final
class in Java at all then?
m
Look at Enum’s equals() 🙂
Generally speaking, typical classes should be final.
c
Unless you are very strict and reject sub-classes
Copy code
if(!getClass().equals(o.getClass())) return false;
1
Yes agree but there are cases when it is not practical. An example is Realm where a proxy class which is a sub-class of your model is created and it is an instance of the proxy class that is returned by queries etc
I would still like to get the boilerplate-free features of data classes without some of the restrictions.
m
Yes, thought about proxies too. Collections also define their own equals(), but they obey a general contract.
c
But thanks for pointing out the transitivity of equals(). I have something to think about now 🙂