What’s new in Kotlin 2.5.0

Introduction
The Kotlin ecosystem never stands still. According to Kotlin's release process, a new language version is released every 6 months, so December 2026 brings us Kotlin 2.5.0 – a milestone release that marks an interesting shift in the language's evolution. While previous K2 iterations were mainly about rapid innovation and experimental leaps, version 2.5.0 strikes a powerful balance: it stabilizes previous game-changing features while also introducing some high-utility experiments.
Whether you're looking to clean up your codebase or explore the cutting edge of language design, let me introduce you to the major and most interesting changes waiting for you in 2.5.0.
What becomes stable
First, let me go through the features that become stable in Kotlin 2.5.0. All of them were introduced either in 2.4.0 or 2.3.0 and now they're becoming a part of the official, stable release.
Improved compile-time constants
This language feature has been introduced as experimental in Kotlin 2.4.0 and it extends the compile-time constants mechanism, improving it for numeric and string types.
Compile-time constants is a Kotlin feature that allows us to tell the compiler which of the read-only properties should be inlined with their values. This is achieved by using the const keyword and makes accessing those properties more efficient.
The feature I'm describing further improved this mechanism for particular elements, like:
- unsigned type operations
- standard library functions for strings (
lowercase(),uppercase(), etc.) nameproperty for enum constants
@IntroducedAt annotation
Kotlin 2.4.0 brought a new @IntroducedAt annotation for preserving binary compatibility when adding new optional parameters to published APIs. It can be used to annotate newly added optional parameters with the version in which they were introduced. This is the information for the compiler to properly generate method overloads.
Take a look at how to use this annotation in your code:
fun doSomeImportantStuff(
whoAsks: User,
whatToDo: Task,
@IntroducedAt("1.1") whenToStart: LocalDate = LocalDate.now(),
@IntroducedAt("1.2") why: String = "because",
assignee: User = whoAsks
) {
// Do the stuff here
}In the example above, the compiler will generate hidden overloads for older versions of the doSomeImportantStuff() function.
It's also worth mentioning that the @IntroducedAt annotation can cause conflicting overloads when used together with the @JvmOverloads annotation. If you suppress the warning, @IntroducedAt will be prioritized.
Unused return value checker
This feature was first introduced as experimental in Kotlin 2.3.0. Since 2.5.0, it will become stable and enabled by default.
Unused return value checker produces a warning when a value other than Unit or Nothing is returned but never consumed.
Check the example below to see when it'll trigger:
fun getErrorMessage(status: String): String {
if (status == "NOT_IN_STOCK") {
return "Not in stock!"
}
if (status == "ERROR_PROCESSING") {
// There will be a warning here, reporting an unused result
"Error while processing the order, status is " + status + "!"
}
return "Something went wrong!"
}Name-based destructuring
Kotlin has supported destructuring declarations since version 1.0.0. In 2.4.0, name-based destructuring was introduced as an experimental feature, becoming stable now in 2.5.0.
"Traditional" position-based destructuring probably doesn't need any explanation to seasoned Kotlin developers. So just in short, it allows you to decompose the object into its properties in a very simple and convenient way. But up to Kotlin 2.4.0, this could have been error-prone, because the compiler wasn't always able to check if the parameters were listed in the proper order, leading to potential bugs. This is where name-based destructuring comes into play, allowing you to explicitly specify which parameter binds to which object property, by name.
Look at the example below to see the difference:
data class BoardGame(val title: String, val author: String)
val boardGame = BoardGame("Super high fantasy adventure", "John Meeple")
fun printBoardGameInfo(boardGame: BoardGame) {
// Old, position-based destructuring; Mistakenly wrong order of parameters used here
val (author1, title1) = boardGame
println("Title: $title1, Author: $author1")
// It will print: "Title: John Meeple, Author: Super high fantasy adventure"
// New syntax of position-based destructuring, introduced in 2.4.0; Still error-prone though
val [author2, title2] = boardGame
println("Title: $title2, Author: $author2")
// Wrong parameters printed out again
// New name-based destructuring
(val author3 = author, val title3 = title) = boardGame
println("Title: $title3, Author: $author3")
// The message will show the appropriate Title and Author
}The main takeaway of this example is the name-based destructuring shown at the end. But you may also want to take a look at the new position-based destructuring syntax introduced, which now uses square brackets. It is meant for the types where the order of elements matters (like collections) or as unnamed tuples (like Pair or Triple).
Kotlin 2.4.0 introduced a new -Xname-based-destructuring compiler option. It gives you control over how the compiler interprets destructuring declarations. It has the following modes:
only-syntaxenables the explicit form of name-based destructuring without changing the behavior of existing destructuring declarations.name-mismatchreports warnings when position-based destructuring in data classes uses variable names that don't match the property names.completeenables short-form name-based destructuring with parentheses and continues supporting position-based destructuring with square bracket syntax.
One important note is that Kotlin 2.5.0 stabilizes name-based destructuring in only-syntax mode, making it also the default mode.
New experimental features
Companion extensions and companion blocks
Tired of declaring companion objects in your Kotlin classes just to have a "container" for some constants, type-level functions, or extensions? Kotlin 2.5.0 has a feature especially for you! This experimental feature allows you to declare:
- companion extensions for types outside of the class definition (even if the class doesn't declare its own companion object).
- functions and properties inside a
companion {}block of a class or interface, without the need for instantiating an object. On JVM, those will be generated as static members, so you don't need to explicitly annotate them with@JvmStatic.
Let's see what this looks like in code:
companion val BoardGame.Draft get() = BoardGame("[Untitlted]", "[Add an author]")
data class BoardGame(val title: String, val author: String) {
companion {
fun GameOfTheYear(boardGame: BoardGame): BoardGame = BoardGame(boardGame.title + " [Game of the Year Edition]", boardGame.author)
}
}
val draft = BoardGame.Draft
val dungeonCrawlerGotY = BoardGame.GameOfTheYear(BoardGame("Dungeon Crawler", "John Meeple"))In the example above, the BoardGame data class has a companion extension Draft and a companion function GameOfTheYear. Neither of these required a companion object.
To use the companion extensions and companion blocks experimental feature, you need to add the -Xcompanion-blocks-and-extensions compiler option to your build file.
Full value classes
In pre-2.5.0 Kotlin versions, value classes were wrappers for single values only. If you'd like your value to have multiple properties, you would need to go with either a regular class or a data class. But you'd lose what value classes give you, which is identity by value, not by reference.
Kotlin 2.5.0 introduces experimental full value classes, which allow you to define value classes wrapping more than one property. For those classes the compiler automatically generates equals(), hashCode() and toString() functions.
It's worth mentioning that for full value classes you can only use name-based destructuring, as position-based destructuring won't work. Also, there is no copy() function.
Let's take a look at how such a full value class might look in code:
value class Token(val value: Int, val resource: String)Some more interesting facts about full value classes in a nutshell:
- Full value classes can be abstract and can define initialization logic that every subclass runs during construction.
- Full value classes with no properties are also allowed, and are called value objects.
- With these new value classes, a value class no longer necessarily means inline.
To enable full value classes in your code, just add the -Xfull-value-classes compiler argument to your build file.
Helper functions for Boolean
Since Kotlin 2.5.0, Boolean has some helper functions that help simplify code and change how the conditional flow is implemented. Instead of always using if-else blocks for verification of the Boolean value before returning it, you can now use one of the following functions:
onTrue()– runs some code when aBooleanvalue istrueand returns the originalBooleanvalue.onFalse()– runs some code when aBooleanvalue isfalseand returns the originalBooleanvalue.ifOrNull()– if theBooleanvalue istrue, runs some code and returns its result. If the value isfalse, the function returnsnullwithout running the block.
Here are some examples below:
fun notVeryReliableRequest(): Boolean =
inGoodMood() && theWeatherIsNice()
fun celebrate(): Unit {
// some really costly operation here
}
@OptIn(ExperimentalStdlibApi::class)
fun main() {
val result1 = notVeryReliableRequest().onTrue {
println("Request succeeded!")
}
val result2 = notVeryReliableRequest().onFalse {
println("Request failed!")
}
val statusMessage = ifOrNull(notVeryReliableRequest()) {
celebrate()
"All good!"
}
println(statusMessage)
}In the example above, both the onTrue() and onFalse() function usages are obvious. When it comes to the ifOrNull() call, it's worth mentioning that the whole block, including an expensive celebrate() function, will not be called in case notVeryReliableRequest() returns false. The status message is null then. But when it returns true, celebrate() is executed and statusMessage is printed as "All good!".
As you might have seen in the example above, to use the experimental Boolean helper methods, you need to annotate your function with @OptIn(ExperimentalStdlibApi::class). You can also use the compiler argument -opt-in=kotlin.ExperimentalStdlibApi instead.
Improved checks for equality comparisons on structural classes
Kotlin 2.5.0 introduces a stricter comparison of structural classes (data classes, data objects, final value classes, and enum classes). With this feature, the compiler issues a warning when you try to compare classes of different types with == or !=, even if they have exactly the same properties.
Check out the example below:
data class BoardGame(val title: String, val author: String)
data class VideoGame(val title: String, val author: String)
fun main() {
val terraformingVenusGame = BoardGame("Terraforming Venus", "John Meeple")
val sunCraftGame = VideoGame("Sun Craft", "Joy Stick")
/*
Warning here that says:
"[INCOMPATIBLE_STRUCTURAL_CLASS_COMPARISON] Comparison is always unsuccessful
because 'BoardGame' and 'VideoGame' are incompatible types with structural equality."
*/
if (terraformingVenusGame == sunCraftGame) {
print("They're the same picture!")
}
}To enable that experimental feature in your project, just set the -Xstrict-equality-for-structural-classes compiler option in your build file.
Support for Unicode code points
Kotlin 2.5.0 introduces the new kotlin.text.unicode.CodePoint class. It is a wrapper over Int and brings some utility functions for Unicode code points. It's mainly meant to work with UTF-16 code points that sometimes consist of two Char code units. As the CodePoint class wraps an Int, not a Char, its single instance always represents the whole Unicode code point.
Take a look at some helper functions that the CodePoint class offers:
val codePoint = CodePoint('a'.code)
println("Digit? : ${codePoint.isDigit()}")
println("Letter? : ${codePoint.isLetter()}")
println("Is a basic (BMP) code point? : ${codePoint.isBasic}")
println("The number of Char values needed to represent this code point: ${codePoint.size}")There are, of course, more of them. You can check all of them in the CodePoint class itself on GitHub.
To enable the experimental CodePoint class in your code, either annotate your function with @OptIn(ExperimentalUnicodeApi::class) or use the -opt-in=kotlin.text.unicode.ExperimentalUnicodeApi compiler option.
Support for Java 28
Last but not least – since Kotlin 2.5.0, the compiler can generate Java 28 bytecode.
Final thoughts
Kotlin 2.5.0 highlights a clear shift towards maturity in the language. Following the major release of the K2 compiler, the focus has naturally moved from rapid feature expansion to stabilization and refining existing capabilities.
Graduating features like name-based destructuring and the unused return value checker directly improve safety and reduce daily bugs in larger projects. At the same time, new experiments like full value classes and companion extensions show that Kotlin continues to innovate with practical, zero-overhead language features.
Overall, Kotlin 2.5.0 shows that the language is evolving pragmatically, focusing on developer productivity and dependable type safety above all.
Reviewed by: Rafał Maciak