Kotlin 1.2 EAP now available

Good news for all Kotlin coders - early access program of Kotlin 1.2 available
19 July 2017   1066
Kotlin

Statically-typed programming language that runs on the Java Virtual Machine and also can be compiled to JavaScript source code.

Kotlin team recently announced the start of the early access program for Kotlin 1.2. First milestone 1.2M1 was out recently. This is reported by official Kotlin Blog

Let's have a good look at the most interesting features of EAP.

Language feature: array literals in annotations

The single notable language feature proposed in this milestone is array literals, whose usages are constrained to annotation arguments.

In order to specify an array of values, coder had to write something like this:

@CacheConfig(cacheNames = arrayOf("books", "default"))
public class BookRepositoryImpl {
    // ....
}

Now, in Kotlin 1.2 a literal can be used instead of the arrayOf function:

@CacheConfig(cacheNames = ["books", "default"])

public class BookRepositoryImpl {

    // ....

}

Additionally, an IDE inspection will propose you to use the new syntax of collection literals where appropriate.

Inline function with optional functional parameters

Earlier, it was impossible to declare an inline higher order function with an optional functional parameter like the following:

inline fun <E> List<E>.printItems(transform: (E) -> String = { it.toString() })

One had to either make the function itself non-inline or mark the functional parameter as noinline. In either case that defeated the purpose of functional parameter inlining.

Now this case is fully supported.

Standard Library API

This release features two KEEPs (Kotlin Evolution and Enhancement Proposals) regarding the standard library API.

The first is KEEP-49 . It provides additional operations and conversion extensions for BigIntegerand BigDecimal types.

The second one is KEEP-11 which covers a number of functions related to partitioning collections and sequences:

  • chunked(size: Int) extension function partitions a collection into blocks of the given size;
  • windowed(size: Int, step: Int) takes a window of the given size and moves it along the collection with the given step returning the sublists of elements falling into each window;
  • pairwise() extension returns all subsequent pairs in a collection.

JavaScript

Earlier in 1.1.2 release developers have introduced the opt-in JS typed arrays support. When enabled it translates Kotlin primitive arrays, such as IntArrayDoubleArray etc, into JavaScript typed arrays. Now the opt-in is no longer required as this support is enabled by default.

You can find more info at changelog and Kotlin Blog.

JetBrains to Roll Out Kotlin/Native 0.8

Version 0.8 of Kotlin/Native brings new features and bug fixes
13 July 2018   137

The project team of Kotlin / Native introduced the release of version 0.8. Corrections and additions have concerned the security of multithreaded programming, the expansion of library functionality and support for iOS devices. As always, alot of bugs are fixed.

Parallelism

Implemented the concept of object freezing

object Config {
  var width: Int = 10
  private set
  init {
    val file = fopen("config.txt", "r")
    if (file != null) {
              try {
              val buffer = ByteArray(2 * 1024)
                 while (true) {
                 val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString()
                 if (nextLine == null || nextLine.isEmpty()) break
                 val records = nextLine.split('=')
                 if (records.size != 2) continue
                 val key = records[0].trim()
                 val value = records[1].trim()
                 when (key) {
                         "width" -> width = value.toInt()
                            }
                          }
                        }
             } finally {
                fclose(file)
                    }
         }
}

This code considers the configuration file and will later receive the Config.width property. 

The Config file itself is divided for any number of threads or vorkers. After publication, the object is frozen and any attempt to change it will result in an exception (InvalidMutabilityException).

The second peculiarity of parallelism in the Kotlin / Native project is indivisible values and references. Let's add an image:

object Config {
private val icon_ = AtomicReference()
val icon: Image
get() = icon_.get()!!
fun updateIcon(file: String) {
val imageData = Image(file)
icon_.compareAndSwap(icon_.get(), imageData.freeze())
}
}

All information about the icon in the AtomicReference is frozen. Any changes are indivisible and similar information is visible to each client.

Kotlin Libraries

Starting v 0.8, the standard library (kotlin. *) is compatible with other platforms. Standard number generator and the function of mixing the collections are designed to eliminate the use of sharpened for a specific platform API. As an experiment, the project supports other libraries, for example, kotlinx.coroutines, kotlinx.serialization, and also the Ktor HTTP client.

Changes for iOS devices

Fixed issues with the publication in the App Store and the initialization of the platform. Support for the 32-bit ARM architecture of iOS processors, which allows using Kotlin / Native on older devices from Apple added.