Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Immutable class - equals() and hashCode() methods ?  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether Immutable class need to implement equals() and hashCode() methods ?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

Usually.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether you need to implement hashCode() and equals() is a separate issue from whether your class is immutable or not.

It's often a good idea to implement hashCode() and equals(), but it's not absolutely required for immutable classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!