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:

  • in the operator (a + bcode), explicit (, 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="" 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!


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.



Access4 holds inaugural A/NZ Annual Conference

Access4 holds inaugural A/NZ Annual Conference

​Access4 held its inaugural Annual Conference in Port Douglass, Queensland, for Australia and New Zealand from 9-11 October, hosting partners from across the region with presentations on Access4 product updates, its 2023 Partner of the Year awards and more.

Access4 holds inaugural A/NZ Annual Conference
Show Comments