https://kotlinlang.org logo
#announcements
Title
# announcements
m

miha-x64

03/14/2017, 1:51 PM
Yes.
c

curioustechizen

03/14/2017, 1:52 PM
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

miha-x64

03/14/2017, 1:53 PM
Look at Enum’s equals() 🙂
Generally speaking, typical classes should be final.
c

curioustechizen

03/14/2017, 1:54 PM
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

miha-x64

03/14/2017, 1:57 PM
Yes, thought about proxies too. Collections also define their own equals(), but they obey a general contract.
c

curioustechizen

03/14/2017, 1:57 PM
But thanks for pointing out the transitivity of equals(). I have something to think about now 🙂
2 Views