Is there a way to use `List`'s indexOf() of a list...
# getting-started
t
Is there a way to use `List`'s indexOf() of a list of a type on another type, for example I have a list of
Product
and
ProductToOrder
which are quite similar in terms of
id
and
name
, I overrode the`equals()` already but
productsToOrder?.indexOf<Any>(product)
always returns
-1
p
I don’t think overriding
equals
is a good idea in this case as you would need to override
equals
and
hashCode
in both classes. Instead you can write:
Copy code
productsToOrder.indexOfFirst {
    it.id == product.id && it.name == product.name
}
t
Waoh thanks