Menu
Kotlin adds dynamic method invocation for JVM

Kotlin adds dynamic method invocation for JVM

Experimental feature in Kotlin 1.4.20 allows string concatenations to be compiled into dynamic invocations for JDK 9 or later targets

Credit: Robert Shunev

JetBrains has released Kotlin 1.4.20, an upgrade to its language for the JVM, Android, and the browser, with an experimental capability for JVM-based string concatenation via the dynamic method invocation leading a list of new features.

String concatenation on the JVM since JDK 9 has been done via the dynamic method invocation, the invokedynamiccode instruction in the bytecode. This is faster and consumes less memory than the previous implementation and leaves room for future optimizations without needing bytecode changes.

This mechanism is now being implemented in Kotlin to improve performance. String concatenations now can be compiled into dynamic invocations for JDK 9 or later targets. The experimental feature can be invoked for the following use cases, via adding the -Xstring-concat option:

  • String.plus in the operator (a + bcode), explicit (a.plus(b)), and reference ( (a::plus)(b) ) forms.
  • toString on inline and data classes.
  • String templates, except for those with a single non-constant argument.

Developers must invoke one of the following rules to use invokedynamic:

  • indy-with-constants to perform invokedynamic concatenation on strings with <a href="https://docs.oracle.com/javase/9/docs/api/java/lang/invoke/StringConcatFactory.html#makeConcatWithConstants-java.lang.invoke.MethodHandles.Lookup-java.lang.String-java.lang.invoke.MethodType-java.lang.String-java.lang.Object...-" rel="nofollow">StringConcatFactory.makeConcatWithConstants()</a>.
  • indy to perform invokedynamic concatenation on strings with StringConcatFactory.makeConcat().
  • inline to switch back to the classic concatenation via StringBuilder.append().

JetBrains announced the release of Kotlin 1.4.20 on November 23. The command line compiler for Kotlin 1.4.20 can be downloaded from GitHub. IntelliJ Idea and Android Studio IDE users can find instructions for updating their Kotlin plug-in here.

Kotlin 1.4.20 also features the following:

  • For Kotlin/JS, new templates are offered for the project wizard. Control over project configuration has been enhanced via an improved DSL capability. The IR compiler has been fitted with a new way to compile projects, ignoring errors in code.
  • The Kotlin/JS Gradle DSL now offers simplified project setup and customization. Also, a single point is offered for webpack configuration.
  • The project wizard for Kotlin has added adjustable templates for Kotlin/JS applications. Templates are featured for browser, Node.js, and React applications.
  • Entries to the package.json file can be made from the Gradle build script.
  • An experimental selective yarn dependency resolutions capability is featured, configurable from the Gradle build script.
  • The JDK 15 target has been added.
  • Behavior inconsistencies between Kotlin/Native and Kotlin/JVM have been fixed in some corner cases, such as property initialization. Also for Kotlin/Native, Objective-C exceptions can be wrapped into Kotlin exceptions.
  • The standard library includes experimental extensions for java.nio.file.Path. Also, the performance of the String.Replace function has been improved.

Follow Us

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Featured

Slideshows

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

Hundreds of leaders from the New Zealand IT industry gathered at the Hilton in Auckland on 17 November to celebrate the finest female talent in the Kiwi channel and recognise the winners of the Reseller News Women in ICT Awards (WIICTA) 2020.

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards
Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

The leading female front runners of the New Zealand ICT industry joined together for the annual Reseller News Women in ICT Awards event at the Hilton in Auckland, during which hundreds of guests celebrated 13 outstanding individuals who won awards, chosen from more than 50 finalists representing over 30 organisations.

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards
Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners

Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners

More than 500 channel leaders gathered in Auckland on 21 October at the ​Reseller News Innovation Awards ​2020 to celebrate the achievements of the New Zealand technology industry's top partners, start-ups, vendors, distributors and individuals.

Channel gathers to celebrate the Reseller News Innovation Awards 2020 winners
Show Comments