Kotlin 1.1.4-3 hotfix released

New hotfix for Kotlin 1.1.4 released; giant amount of bugs fixed
31 August 2017   525

A hotfix for latest Kotlin version 1.1.4 has been released. Let's see what it fixes.

List of fixed bugs:

  • SamWithReceiver compiler plugin not used by IntelliJ for .kt files
  • Gradle Kotlin Plugin does not work with the gradle java-library plugin
  • Console spam when opening idea-community project in debug IDEA
  • [Coroutines + Kapt3] Assertion failed in ClassClsStubBuilder.createNestedClassStub
  • kapt3 & Parcelize: Compilation error
  • Kotlin 1.1.4 noarg plugin breaks with sealed classes
  • Kapt error after updating to 1.1.4 - stub adds type parameters where there are none
  • Mocking of final named suspend methods with mockito fails
  • kapt3: not always including argument to @javax.inject.Named in generated stubs
  • "Convert to expression body" is not shown in 162 / AS23 branches for multi-liners
  • NPE caused by Map<String, Boolean>?.get
  • PerModulePackageCacheService calls getOrderEntriesForFile() for every file, even those that can't affect Kotlin resolve
  • Provide an opt-out flag for separate classes directories (Gradle 4.0+)
  • if an imported library already exists it should be redetected during gradle import

Learn more at GitHub

How to convert list to map in Kotlin

Two ways to convert list to map in Kotlin, with code examples
31 October 2017   515

For example, you have a list of strings like:

val list = listOf("a", "b", "c", "d")

and you need to convert it to a map, where the strings are the keys.

There are two ways to do this:

The first and most performant is to use associateBy function that takes two lambdas for generating the key and value, and inlines the creation of the map:

val map = friends.associateBy({it.facebookId}, {it.points})

The second, less performant, is to use the standard map function to create a list of Pair which can be used by toMap to generate the final map:

val map = friends.map { it.facebookId to it.points }.toMap()