Kotlin lead designer Michail Zarečenskij
The Kotlin language, developed by JetBrains and open source under the Apache2.0 licence, began in 2011 as an alternative to Java for applications that run on the JVM (Java Virtual Machine), but since then has evolved to target JavaScript, mobile platforms, native executables and web assembly.
Kotlin lead designer Michail Zarečenskij spoke to DevClass about the relationship with Java and the future of the language.
"The Kotlin language appeared as an alternative for Java and at the time we wanted to address some of its limitations and issues such as nullability story, check exceptions, invariant arrays and so on," he told us.
"Over the years Kotlin has evolved, and now we have this Kotlin multiplatform story and we can target multiple platforms such as iOS, Android and so on, we have Kotlin Notebook, we have Compose which is a framework to write UI in Kotlin, and we have build.gradle.kts where it's possible to wirte Gradle scripts in Kotlin, but still the JVM segment and Java are very, very important for us, actually crucial. We still want to be interoperable with Java because we totally understand that Java is going to be with us for many, many years and we don't want to completely replace Java. It's just not possible and it's not our goal," he said.
There are cases where Kotlin is waiting for Java, or JVM, features to be implemented. "I would love if Java can release Project Valhalla sooner because all the users of the JVM will benefit from it," he said.
Project Valhalla will bring value types and more to the JVM.
"Project Vahalla and value classes feed [into] Kotlin really well, because many applications are going to be around mathematics," said Zarečenskij . It may also enable Kotlin to have operator overloading where "you do not have to write .plus, but actually write +" or other standard symbols. "This is where Kotlin shines, so we are eager to see value types on the JVM so that we can adopt this feature and make it even more expressible in Kotlin," he said.
Does the Kotlin team work with the committees that evolve the Java language? "It really depends on the feature," Zarečenskij told us. "We communicate, and we are looking closely at things like value classes because mostly it's a JVM feature ... we'll have to adjust some of its design and be aware of design decisions so that the JVM will successfully optimize value classes for Kotlin as well."
Java has recently implemented virtual threads, part of Project Loom, what are the implications for Kotlin's coroutines which are also used for concurrent programming?
"Their goals are slightly different," Zarečenskij said. "Project Loom still utilizes the Thread API. It's the same API we've had for many years with all the advantages and disadvantages. In Kotlin we have structured concurrency, this parent to child relationship between coroutines. So it's easier to communicate between them, to cancel them, or to handle errors if there's an exception in one of the coroutines. If you have this fine-grained concurrency and you want to write a new application, then Kotlin coroutines might be better."
He added that, "one of the disadvantages of Kotlin coroutines is that if you have a suspend function which actually uses Thread API under the hood, we still use the physical thread. What we actually want to do is to enable Project Loom for Kotlin coroutines, so if you have to use Threads, you will be able to use virtual threads ... then you have the best of two worlds."
Kotlin has been boosted by Google's adoption of the language as primary for Android development. Does that account for most of its usage?
"Most usage is still in Android, but around 40 to 45 percent of Kotlin users are writing server-side applications," said Zarečenskij. "And we see that the multi-platform story is growing."
There is no official JetBrains implementation of the Language Server Protocol (LSP) for Kotlin. This is used by non-JetBrains IDEs such as Visual Studio Code to enable smart programming language support in the editor, debugging and more. Is that intended to keep developers within the JetBrains family of IDEs or could it change in future?
"The LSP story is very interesting and at some point it will become essential for us I think," said Zarečenskij. "We would love to have a proper LSP for Kotlin because if Kotlin can be presented on many IDEs with good support, it's a benefit for Kotlin. But the way LSP was designed, for example, it doesn't allow to communicate between Java and Kotlin. One of our key features is interoperability, but If you call to Kotlin from Java, it's not possible to go into the Java LSP and navigate to the Kotlin LSP. So we don't have a proper LSP from JetBrains. There is at least two implementations in open source, and I saw that the people who develop those started to work on a new version that will utilize the K2 API, because it has a nice API for analysis.
"I hope it will take off and you will have a proper Kotlin LSP. But there will be issues with interoperability."
K2 is the recently released new compiler for Kotlin.
What is coming next in Kotlin? "Key features are immutabilty, and a new error model," said Zarečenskij. He added that he expects a surge of new language features "because K2 is finished, and now we work on the language." More will be revealed at the next KotlinConf scheduled for May 2025, in Copenhagen.