• The Road to Kotlin 1.5
  • By Michael Redlich
  • The Nuggets translation Project
  • Permanent link to this article: github.com/xitu/gold-m…
  • Translator: samyu2000
  • Proofread by: Kimhooo, PassionPenguin, PingHGao

Towards the Kotlin 1.5

JetBrains has released Kotlin 1.4.30, which contains some experimental features to pave the way for the upcoming 1.5 stable release, a milestone in Kotlin’s history. As this is the last release in the 1.4.x series, these new features include a JVM backend IR compiler, support for the Java Record keyword and Sealed Interface, and support for the Kotlin Gradle Plugin. JetBrains encourages members of the Kotlin technical community to use version 1.4.30 in their applications to test these new features, particularly the JVM backend IR compiler, and to feed back bugs encountered through YouTrack.

The JVM backend IR compiler, currently in beta, is used to analyze source code and complements the predecessor compiler, which will be the default compiler in Kotlin 1.5. It consists of three separate back-end components: Kotlin/JVM, Kotlin/JS, and Kotlin/Native. The first two are independently developed by JetBrains and will work with Kotlin/Native to form the new JVM IR infrastructure.

Backend changes include Bug fixes and new features to improve performance that were present in the original backend. The new toolkit and Jetpack Compose for building Android UIs will only work on the new backend.

JetBrains marketing director Alina Grebenkina describes the benefits of combining the three back-end components. She also writes:

Much of the back-end logic is shared and has a uniform pipeline, so most features, optimizations, and Bug fixes can be done at once for any requirement.

A unified back-end infrastructure enables compilers to be used across platforms. It helps to turn on pipes and add some custom processing and transformation, and is automated and applicable to all requirements.

With the release of Java 16, Kotlin also supports a new data type, ———— Record, so Kotlin and Java can interoperate. The type of Record in Java can be declared in Kotlin using the @jVMRecord annotation:

@JvmRecord
data class User(val name: String, val age: Int) 
Copy the code

The compiler must set -xJVM-enable-preview and -language-version 1.5 to test this new feature.

The sealing interface in Kotlin complements the sealing class by creating a more flexible sealing class hierarchy. Thus, a derived class can inherit multiple sealed interfaces:

sealed interface Fillable {
    fun fill(a)
}

sealed interface Polygon {
    val vertices: List<Point>
}

class Rectangle(override val vertices: List<Point>): Fillable, Polygon {
    override fun fill(a) {
        / *... * /}}Copy the code

To improve build efficiency, the Kotlin Gradle plugin is now compatible with Gradle Configuration Cache, a Gradle configuration cache that is not widely used. This feature is designed to speed up builds by caching the results of the configuration phase and reusing them in subsequent builds. Consider the following example:

$ gradle --configuration-cache help
Calculating task graph as no configuration cache is available for tasks: help. BUILD SUCCESSFULin 4s
1 actionable task: 1 executed
Configuration cache entry stored.
Copy the code

Executing the same command again will print:

$ gradle --configuration-cache help
Reusing configuration cache.
...
BUILD SUCCESSFUL in 500ms
1 actionable task: 1 executed
Configuration cache entry reused.
Copy the code

Notice how long each build takes. This plug-in requires Gradle 5.4 or higher support. For more information on configuring caching, visit Gradle’s official documentation.

Last fall, JetBrains announced that it would release a new version of Release Cadence, allowing a new version of Kotlin to be released every six months.

For more information about this release, see the Highlights section of the Kotlin documentation.

If you find any mistakes in your translation or other areas that need to be improved, you are welcome to the Nuggets Translation Program to revise and PR your translation, and you can also get the corresponding reward points. The permanent link to this article at the beginning of this article is the MarkDown link to this article on GitHub.


The Nuggets Translation Project is a community that translates quality Internet technical articles from English sharing articles on nuggets. The content covers Android, iOS, front-end, back-end, blockchain, products, design, artificial intelligence and other fields. If you want to see more high-quality translation, please continue to pay attention to the Translation plan of Digging Gold, the official Weibo, Zhihu column.