BT

InfoQ Homepage News Kotlin 1.4 Brings New Language Features, Improved Compilers and Tools

Kotlin 1.4 Brings New Language Features, Improved Compilers and Tools

Bookmarks

Kotlin 1.4 focuses on improving performance and tooling. It also contains a number of new language features, including single abstract method (SAM) conversion for interfaces, explicit API mode, and more.

Our main focus for this release was improving the overall development experience with Kotlin, including improved IDE performance and stability. Our goal is to make Kotlin users as productive as possible, and we focused on improving the things that are most important to users, so they feel even happier when using it!

Kotlin plugin for IntelliJ IDEA 2020.1+ and Android Studio 4.1+ fixes more than 60 performance issues. Thanks to this, for example, syntax highlighting is now 1.5-4 times faster, says JetBrains. Similarly, autocomplete suggestions take less time to appear, with 95.4% of cases requiring less than 500ms, up from 92.4% in the previous release, and only 1.3% of cases requiring more than 1s.

JetBrains has also released parts of the new Kotlin compiler front-end, which aims to be much faster and unify all supported platforms. In particular, the latest compiler uses a more powerful type inference engine and includes new, alpha-quality JVM and JS backends.

The new type inference engine extends the number of cases where types can be inferred, supports smart cast for lambdas's last expression and callable references, and more. Kotlin/JVM and Kotlin/JS have been migrated to use the same IR as Kotlin/Native, which enables implementing most features, optimizations, and bug fixes only once for all platforms.

Speaking of language features, Kotlin 1.4 contains many new features, including single abstract method (SAM) conversion for interfaces, explicit API mode for libraries, support for mixing named and positional arguments, trailing comma, and others.

Single abstract method conversion is a feature that existed in previous Kotlin releases but could only be used with Java methods and interfaces. Now, it can be also used for Kotlin interfaces. In short, single abstract method conversion enables passing a lambda as an argument when an interface with just one single abstract method is expected:

fun interface IntPredicate {
    fun accept(i: Int): Boolean
}

val isEven = IntPredicate { it % 2 == 0 }

fun main() { 
    println("Is 7 even? - ${isEven.accept(7)}")
}

When using explicit API mode, Kotlin compiler enforces two specific rules meant to improve library interfaces: if default visibility is public, visibility modifiers are required for all declarations to prevent any of them from being exposed unintentionally; similarly, explicit type specifications are required with properties and functions belonging to the public API.

Other convenient language features Kotlin 1.4 includes are support for mixing named and positional arguments and for trailing comma. In Kotlin 1.4 you can specify a named argument in the middle of positional arguments and you can mix named and positional arguments freely, provided they remain in the correct order. Trailing comma is allowed in argument and parameter lists, in when entries, and in destructuring declarations.

On the tooling front, worth mentioning are a new project wizard and a coroutine debugger which allows you to check the status of each coroutine, inspect values of local and captured variables, and inspect the call stack leading to the coroutine call as well as the frames belonging to the coroutine itself.

Kotlin 1.4 is in all respect a major version including a lot of new stuff which cannot be covered entirely here. Do not miss the official release notes for the full detail.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Nice!

    by Cameron Purdy /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Kotlin continues to impress people whom I talk to who are using it. People really seem to enjoy using it, which is about as big of a compliment as a language can get!

  • Re: Nice!

    by Andrew McVeigh /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    i've found programming in kotlin a genuinely pleasant experience, which surprised me as I initially saw it as a cross between a smarter Java or a dumber Scala. it feels like it has hit a sweet spot of learnability and expressivity. i'm rewriting a typescript/react app in kotlin/js right now, and redoing the node backend in kotlin/jvm. loving the dsl side also

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.