October 2025
Intermediate to advanced
100 pages
2h 27m
English
All the speakers were added to both conference days. Why?
A data class’s copy function creates a shallow copy. Only one object is actually copied—the Event itself. For everything stored inside the object, the new Event just points at the same values as the old one.
Since both objects end up pointing at the same ArrayList object, any modifications to the list are visible in both.
When we created our first Event object, we didn’t supply a speakers value. Kotlin used the default from the class constructor, which creates a new ArrayList.
But for our second Event, we used copy, which doesn’t use the constructor defaults. Instead, for any property where you don’t supply a new value, copy takes the corresponding value ...
Read now
Unlock full access