Kotlin Features by Version Quick Reference
From Kotlin 1.0 released in 2016 to 2.2 in 2025, the language spent a decade filling in capabilities and stabilizing experimental features.
This chapter reviews key new features in version order and gives migration advice for upgrading from older versions, helping you decide in real projects which syntax can be used and from which version.
Version timeline
First build an overall picture: what problem each major version solved and when it became safe to use.
The table below lists release dates and milestone features from 1.0 to 2.2.
| Version | Release date | Milestone features |
|---|---|---|
| 1.0 | February 2016 | First official release, JVM target stable |
| 1.1 | March 2017 | Experimental coroutines introduced, typealias, sealed subclasses in the same file |
| 1.2 | November 2017 | Multiplatform projects, expect/actual |
| 1.3 | October 2018 | Inline classes, unsigned types, contracts |
| 1.4 | August 2020 | SAM conversion, sealed interface, trailing commas |
| 1.5 | May 2021 | Value classes stable, JVM records, invokedynamic string concatenation |
| 1.6 | November 2021 | Exhaustive when statements over sealed classes, coroutines stable |
| 1.7 | June 2022 | K2 compiler Alpha, ..< operator |
| 1.8 | December 2022 | Enum.entries、data object |
| 1.9 | July 2023 | ..< stable, data object and entries stabilized |
| 2.0 | May 2024 | K2 compiler officially released, when guards, enhanced smart casts |
| 2.1 | November 2024 | Context parameters refactor, nested typealias |
| 2.2 | June 2025 | when guards stable, non-local break/continue stable |
Tip:This chapter uses Kotlin 2.2 as the baseline. Features marked "Experimental" or "Preview" in the table need extra opt-in or the @OptIn annotation; use them cautiously in production projects.
1.0 to 1.4: Filling in core language capabilities
These four versions mainly answered "can Kotlin do a certain thing?"; much of the syntax we take for granted today was introduced at this stage.
1.1: Coroutines, typealias, and sealed in the same file
Coroutines first appeared as an experimental feature in this version and later became Kotlin's core solution for asynchronous tasks.
typealias gives complex types short names, making function types and generic signatures much cleaner.
The restriction on sealed class subclasses was relaxed from "must be nested" to "same file is enough".
Example
// File path: src/main/kotlin/com/runoob/TypeAliasDemo.kt
package
com.runoob
// Type aliases supported since Kotlin 1.1
typealias UserId
=
Int
// Since Kotlin 1.1, sealed class subclasses only need to be in the same file
sealed
class
State
class
Loading
:
State
(
)
class
Done
:
State
(
)
fun findUserName
(
id
:
UserId
)
:
String
=
"User $id"
fun main
(
)
{
println
(
findUserName
(
1001
)
)
}
The output is as follows.
用户 1001
By Kotlin 1.5, the restriction was further relaxed to "same package and module", no longer requiring the same file.
1.2: expect/actual and multiplatform
1.2 gave Kotlin real multiplatform capability: common code uses expect declarations and each platform provides actual implementations.
This is the foundational mechanism of Kotlin Multiplatform.
Example
// File path: src/commonMain/kotlin/com/runoob/Platform.kt
// Common source set: declare only, no implementation
expect fun platformName
(
)
:
String
fun greet
(
)
:
String
=
"Running platform: ${platformName()}"
Example
// File path: src/jvmMain/kotlin/com/runoob/Platform.jvm.kt
// JVM source set: provides the actual implementation corresponding to expect
actual fun platformName
(
)
:
String
=
"JVM"
When calling greet(), the output on the JVM platform is as follows.
运行平台:JVM
1.3: Inline classes, unsigned types, and contracts
Unsigned integer types added UInt, ULong and others, so you no longer need to work around the sign bit when handling binary protocols.
Contracts let developers tell the compiler about a function's behavior, thereby improving smart casts.
Example
// File path: src/main/kotlin/com/runoob/UnsignedDemo.kt
package
com.runoob
import
kotlin.contracts.ExperimentalContracts
import
kotlin.contracts.contract
// Unsigned integer types introduced in Kotlin 1.3, stable since 1.5
val maxValue
:
UInt
=
UInt.
MAX_VALUE
// Contracts introduced in Kotlin 1.3: a normal return means the argument is not null
// The contracts API is still experimental and requires @OptIn to use
@OptIn
(
ExperimentalContracts
::
class
)
fun requireText
(
value
:
String
?
)
:
String
{
contract
{
returns
(
)
implies
(
value
!=
null
)
}
if
(
value
==
null
)
throw
IllegalArgumentException
(
"Content cannot be empty"
)
return
value
}
fun main
(
)
{
println
(
maxValue
)
println
(
0xFFu
)
val text
:
String
?
=
"RUNOOB"
println
(
requireText
(
text
)
.
length
)
}
The output is as follows.
4294967295
255
6
The inline class introduced in this version was renamed to value class in 1.5; see the next section.
1.4: SAM conversion, sealed interface, and trailing commas
fun interface lets Kotlin's own interfaces be implemented with lambdas, no longer needing special conversions for Java interfaces.
sealed interface fills a missing piece in the sealed hierarchy, while trailing commas make diffs of multiline lists cleaner.
Example
// File path: src/main/kotlin/com/runoob/SamDemo.kt
package
com.runoob
// Since Kotlin 1.4, interfaces declared as fun interface support SAM conversion
fun
interface
ClickHandler
{
fun onClick
(
name
:
String
)
}
// sealed interface supported since Kotlin 1.4
sealed
interface
Result
data
class
Success
(
val data
:
String
)
:
Result
data
class
Failure
(
val message
:
String
)
:
Result
fun main
(
)
{
// implement the interface directly with a lambda
val handler
=
ClickHandler
{
println
(
"Clicked $it"
)
}
handler.
onClick
(
"RUNOOB"
)
// trailing commas in multiline parameter lists allowed since 1.4
val site
=
mapOf
(
"name"
to
"Runoob"
,
"url"
to
"www.runoob.com"
,
)
println
(
site
)
}
The output is as follows.
点击了 RUNOOB
{name=Runoob, url=www.runoob.com}
1.5 to 1.9: Stabilization and practicality
The keyword for these versions is "stability": many experimental features became official, while the K2 compiler began taking shape.
1.5: Value classes, JVM records, and invokedynamic
Inline classes were officially renamed to value classes and stabilized; wrapping primitives with them avoids extra object allocation.
JVM targets 9 and above use invokedynamic for string concatenation by default, which is more efficient at runtime.
Example
// File path: src/main/kotlin/com/runoob/ValueClassDemo.kt
package
com.runoob
// Value classes stable since Kotlin 1.5; after compilation most scenarios produce no wrapper object
@JvmInline
value
class
UserId
(
val value
:
Int
)
fun main
(
)
{
val id
=
UserId
(
1001
)
println
(
id.
value
)
println
(
id
)
}
The output is as follows.
1001
UserId(value=1001)
For interoperability with Java records, you can annotate a data class with @JvmRecord, provided JDK 16 or above.
Example
// Declaring JVM records supported since Kotlin 1.5, requires JDK 16+
@JvmRecord
data
class
Point
(
val x
:
Int, val y
:
Int
)
1.6: Sealed when and stable coroutines
Previously, when was required to be exhaustive only as an expression; since 1.6, when used as a statement must also cover all branches.
Coroutines reached stability in this version, and suspend functions can be used as supertypes.
Example
// File path: src/main/kotlin/com/runoob/SealedWhenDemo.kt
package
com.runoob
sealed
class
State
object Loading
:
State
(
)
object Done
:
State
(
)
// Since Kotlin 1.6, when statements (not just expressions) must also be exhaustive
fun describe
(
state
:
State
)
{
when
(
state
)
{
Loading
->
println
(
"Loading"
)
Done
->
println
(
"Done"
)
}
}
fun main
(
)
{
describe
(
Loading
)
describe
(
Done
)
}
The output is as follows.
加载中
完成
1.7: K2 Alpha and ..< operator
K2 is Kotlin's next-generation compiler frontend; it entered Alpha in 1.7 and can be tried early via a flag.
The same version introduced the half-open range operator ..<, so you no longer need to write minus one when iterating up to the boundary.
Example
// File path: src/main/kotlin/com/runoob/RangeDemo.kt
package
com.runoob
fun main
(
)
{
// Kotlin 1.7 introduced the ..< operator, stable since 1.9
for
(
i in
0
..
<
3
)
{
println
(
i
)
}
}The output is as follows.
0
1
2
1.8: Enum.entries and data object
entries replaces values(), returning an immutable list with clearer semantics and better efficiency.
data object gives singleton objects auto-generated toString and equals.
Example
// File path: src/main/kotlin/com/runoob/EntriesDemo.kt
package
com.runoob
enum
class
Color
{
RED, GREEN, BLUE
}
// data object supported since Kotlin 1.8
data object Runoob
{
const
val SITE
=
"www.runoob.com"
}
fun main
(
)
{
// Since 1.8, entries is recommended over values()
Color
.
entries
.
forEach
{
println
(
it
)
}
println
(
Runoob
)
println
(
Runoob.
SITE
)
}
The output is as follows.
RED
GREEN
BLUE
Runoob
www.runoob.com
1.9:..< Stabilized with entries and data object
1.9 promoted the experimental features introduced in 1.7 and 1.8 to official status, safe for production use.
At the same time, values() was marked deprecated since 1.9.20; new code should uniformly use entries.
Example
// File path: src/main/kotlin/com/runoob/StableDemo.kt
package
com.runoob
enum
class
Color
{
RED, GREEN, BLUE
}
data object Runoob
{
const
val SITE
=
"www.runoob.com"
}
fun main
(
)
{
// ..< stable since 1.9
println
(
(
0
..
<
3
).
toList
(
)
)
// entries stable since 1.9
println
(
Color
.
entries
.
map
{
it.
name
}
)
// data object stable since 1.9
println
(
Runoob
)
}
The output is as follows.
[0, 1, 2]
[RED, GREEN, BLUE]
Runoob
2.0 to 2.2: The K2 era
These three versions revolve around the K2 compiler, moving language features from "usable" to "nice to use".
2.0: K2 compiler officially released
K2 is a rewritten compiler frontend: faster compilation, with stronger type inference and smart casts.
when guard conditions were introduced as an experimental feature in this version, allowing an extra condition on a branch.
Example
// File path: src/main/kotlin/com/runoob/WhenGuardDemo.kt
package
com.runoob
sealed
interface
Response
data
class
Ok
(
val body
:
String
)
:
Response
data
class
Error
(
val code
:
Int
)
:
Response
fun handle
(
response
:
Response
)
:
String
=
when
(
response
)
{
is Ok
->
"Success: ${response.body}"
// Guard conditions: introduced in 2.0, stable since 2.2
is
Error
if
response.
code
==
404
->
"Page not found"
is
Error
->
"Error code ${response.code}"
}
fun main
(
)
{
println
(
handle
(
Ok
(
"RUNOOB"
)
)
)
println
(
handle
(
Error
(
404
)
)
)
println
(
handle
(
Error
(
500
)
)
)
}
The output is as follows.
成功:RUNOOB
页面不存在
错误码 500
K2 also enhances smart casts; for example, when a variable is modified after a check, the compiler can infer more accurately.
2.1: Context parameters refactor and nested typealias
2.1 refactored the former context receivers into context parameters, whose syntax is closer to ordinary parameters.
This feature is still in preview in 2.2; you must add the -Xcontext-parameters flag when compiling, otherwise you'll get "the feature "context parameters" is experimental".
Nested typealias allows declaring type aliases inside a class or interface, improving encapsulation.
It also needs explicit opt-in; the compiler flag is -Xnested-type-aliases.
Example
// File path: src/main/kotlin/com/runoob/ContextDemo.kt
package
com.runoob
class
Logger
{
fun log
(
message
:
String
)
=
println
(
message
)
}
// context parameters syntax introduced in Kotlin 2.1 (preview feature)
context
(
logger
:
Logger
)
fun greet
(
name
:
String
)
{
logger.
log
(
"Hello, $name"
)
}
fun main
(
)
{
// provide context parameters via implicit receivers
with
(
Logger
(
)
)
{
greet
(
"Runoob"
)
}
}
The output is as follows.
Hello, Runoob
Example
// File path: src/main/kotlin/com/runoob/NestedAliasDemo.kt
package
com.runoob
class
User
{
// nested type aliases supported since Kotlin 2.1 (preview feature)
typealias Id
=
Int
fun find
(
id
:
Id
)
:
String
=
"User $id"
}
fun main
(
)
{
println
(
User
(
)
.
find
(
1001
)
)
}
The output is as follows.
用户 1001
2.2: Stable when guards and non-local break/continue
when guard conditions became stable in 2.2 and no longer require the @OptIn annotation.
Non-local break and continue also stabilized; jumps inside a lambda can directly affect an outer loop.
Example
// File path: src/main/kotlin/com/runoob/NonLocalBreakDemo.kt
package
com.runoob
fun main
(
)
{
// Stable since 2.2: break inside a lambda can break out of an outer for loop
for
(
i in
1
..
3
)
{
listOf
(
1
,
2
,
3
)
.
forEach
{
if
(
it
==
2
)
break
// break out of the outer loop directly
(
"$i-$it "
)
}
}
println
(
)
}
The output is as follows.
1-1
The loop breaks out directly in the first inner iteration when it reaches 2, so it prints only 1-1 before ending.
Migration advice
Upgrading Kotlin is not simply changing a number; compatibility issues must be handled in order.
New projects can directly use Kotlin 2.2 and the K2 compiler, with no legacy baggage to consider.
Existing projects should upgrade one major version at a time, running tests after each step before continuing; don't jump multiple major versions at once.
| Stage | To-do list | Notes |
|---|---|---|
| Before upgrading | Confirm compatible versions of Gradle, IDE, and compiler plugins | kapt, Compose, and serialization plugins must be upgraded in sync |
| Upgrade to 1.9 | Replace values() with entries, and toUpperCase() with uppercase() | values() has been deprecated since 1.9.20 |
| Upgrade to 2.0 | Switch to the K2 compiler and clean up deprecated syntax | Verify in a small module first, then switch over fully |
| Upgrade to 2.1 | Evaluate context parameters and nested typealias | both are preview features, use cautiously in production code |
| Upgrade to 2.2 | Enable when guards and non-local break/continue | Remove the corresponding @OptIn annotations |
Gradle projects can control compatibility via languageVersion and apiVersion in the kotlin configuration block, relaxing them gradually.
Example
// File path: build.gradle.kts
kotlin
{
compilerOptions
{
// The language version decides which syntax is available; keep it aligned with the old version first, then raise it gradually
languageVersion.
set
(
org.
jetbrains
.
kotlin
.
gradle
.
dsl
.
KotlinVersion
.
KOTLIN_2_2
)
// The API version decides which standard library APIs can be called; it should be less than or equal to the language version
apiVersion.
set
(
org.
jetbrains
.
kotlin
.
gradle
.
dsl
.
KotlinVersion
.
KOTLIN_2_2
)
}
}
The most common errors during upgrades come from deprecated APIs; treating compiler warnings as a to-do list and handling them one by one is often safer than upgrading all at once.
Note:Preview features need explicit opt-in and may change syntax in later versions; confirm the stability notes in the official docs before adopting them in production.
Common questions
The following questions often come up when choosing versions and upgrading.
What is K2 and how does it relate to Kotlin versions
K2 is the codename for the next-generation compiler frontend, not a separate language version.
It entered Alpha in Kotlin 1.7, Beta in 1.9, and became the default compiler in 2.0.
How to check the Kotlin version used by the current project
Run kotlinc -version on the command line, or ./gradlew buildEnvironment in a Gradle project to view the plugin version.
How to enable preview features
Enable them with the corresponding compiler flag, or add the @OptIn annotation in code.
For example, when guards need the preview flag in 2.0 and 2.1, but no longer need it once stable in 2.2.
What to do if compilation fails after upgrading
First check the version hints in the error message; most cases are a removed API or changed syntax.
You can pin back to the old version with languageVersion, fix the issues one by one, then relax it.