Ignore variable with .contains method in kotlin?

Ignore an attribute from contains function. I mean if an attribute value changes it still be the same object.

I have implemented tracking of object in RecyclerView android. Now When some product is favourite by clicking a heart icon. One of it’s attribute

 isFavourite = true /// become true

I have implemented tracking like

 if(isPresent() && shownTrackablePositions.contains(it).not()){
       it.trackView()
       trackableCollectionCallback?.onTrackedItem(it,position)
       shownTrackablePositions.add(it)
 }   

Now after selecting heart icon from any product . An attribute name isFavourite got updated in the database. I want to ignore that variable from contains.

I have tried to write a data class in kotlin and put isFavourite out of the base constructor So that equal , hash etc don’t work on it.

But contains function match all attributes. How could I ignore a var from contains.

  • 1

    Why do you think that “contains function match all attributes”? It uses equals() under the hood, so your solution about excluding isFavourite from the base constructor should work

    – 

Leave a Comment