October 2025
Intermediate to advanced
100 pages
2h 27m
English
Even when two lambda expressions contain exactly the same code, Kotlin doesn’t consider them equal. Each lambda expression creates a new function stored in a separate memory location.
So, our attempt to remove a lambda function from our tasks list has no effect. The function object we’re passing to remove isn’t found in the collection, because it’s a different object from the one we added. At the end of the program, the task list still contains all the tasks, and no items have been removed.
We can see the problem clearly if we reduce it to a simple equality check:
| | println({ "Eat ice cream" } == { "Eat ice cream" }) // → "false" |
When you run this code, you’re not checking whether "Eat ice cream" is equal to ...
Read now
Unlock full access