mikepenz/FastAdapter

Default equals() for Model items

Benjiko99 opened this issue · 2 comments

About this issue

It would be convenient for the ModelAbstractItem and ModelAbstractBindingItem to override equals() and hashCode() to account for the model parameter. Most if not all implementations of those classes will have no other parameters, thus a default equals implementation would remove the need for boilerplate.

It could get rid of all this boilerplate 🥳

override fun equals(other: Any?): Boolean {
    if (!super.equals(other)) return false

    other as MyModelItem
    if (model != other.model) return false
    return true
}

override fun hashCode(): Int {
    var result = super.hashCode()
    result = 31 * result + model.hashCode()
    return result
}

Details

  • [5.3.4] Used library version

Checklist

@Benjiko99 good point. Mainly concerned about backwards compatibility for this, as it most likely could result in behaviour changes for people

Thinking some more through this. I believe that the default behaviour should stay as it is. It will compare items based on their identifier.

If you need the above proposed equals and hash functions more often in your projects, I would suggest that you define an abstract implementation for your usecase working as expected