Default arguments, named parameters, data classes and exhaustive when make Kotlin pleasant to use. They also make it easy to break the code that uses your library without noticing. Here are seven changes that compile and pass your tests, what happens to callers, and what to do instead. We checked each one with Kotlin 2.2.20.
Two ways to break a caller
As in Java, a change can break callers in two ways:
Source compatibility: does the caller's code still compile against the new version?
Binary compatibility: does code that was compiled against the old version still run with the new jar?
The second one matters because applications rarely recompile the other libraries they depend on. Kotlin adds its own traps on top of the Java ones , because several of its features are compiled into code that lives in the caller, not in your library.
In each example, version 1.0 is the release that callers use and 1.1 is the change. The error messages are the real ones.
1.…