Contracts in Kotlin
summary
Kotlin introduces explicit contracts so the compiler can rely on a function’s behavior instead of expensive interprocedural analysis. Contracts express logical implications (for example: if a function returns true then an argument is a String) and invocation counts (notably exactly-once invocation) to enable safe smartcasts and initialization inside lambdas. The team implemented a prototype in a compiler fork, exposed experimental syntax in Kotlin 1.3 for standard-library helpers, and notes there is no verification yet and many open issues remain (runtime checks, Java interop, inheritance, verbosity).
AI-written summary · about
chapters (6)
- 0:00Start
- 0:49Motivating example
- 16:17Open questions
- 19:11Use-case #1. Thread affinity
- 23:29Use-case #2. Safe builders
- 31:51Current state








