Kotlin logo

Kotlin

A concise multiplatform language developed by JetBrains

Releases

Kotlin 1.0 Beta 2 is Out!

The first update to our Beta is here! We are stabilizing, so it’s mostly bug-fixing and changes to the standard library.

Language changes

We are now enforcing single-instantiation inheritance constraint on type parameters: the same T can not have both List<Int> and List<String> as its upper bounds. This has been always forbidden for classes, now the same check applies for type parameters.

Diagnostics were improved for the cases when a smart cast is impossible:

class C {
    var x: String? = ""
    fun foo(): String {
        if (x != null) return x // ERROR: smart cast to String is impossible, 
                                // because 'x' is a member variable
    }
}

Also, the compiler is now smart enough to warn us when a value is always null at a particular point:

    var x: Foo? = ...
    if (x != null) return
    x?.bar() // WARNING: bar() will never run, because x is always null here

Library changes

We cleaning up the APIs of the standard library. Most visible changes this time concern ranges. We intended the common use cases such as “if (x in 1..10)” or “for (i in 1..10)” to remain without changes, but did some renaming and hierarchy rearrangements under the hoods:

  • Double and Float progressions are dropped
  • Byte and Short progressions are deprecated, the .. operator for bytes and shorts now returns IntRange
  • Range<T> renamed to ClosedRange<T> and its end property renamed to endInclusive
  • Progression<T> is deprecated in favor of concrete progression implementations instead: IntProgression, LongProrgession, CharProgression
  • start and end properties in progressions are renamed to first and last

Then, utility extensions for strings were generalized to work with CharSequence where possible.

The filterIsInstance extension now requires an explicit specification of its type parameter:

foo(list.filterIsInstance()) // error: what is the type the checks are done for?!
foo(list.filterIsInstance<Bar>()) // OK: we are checking for Bar

NOTE: To reduce the size of the runtime library (which is especially important for Android applications), we removed the kotlin.dom and kotlin.browser packages from the standard library. They are now available as a separate library, kotlinx.dom. If you’re using any of these packages in your project, please add the new library as a dependency and update the import statements in your code (change kotlin.dom and kotlin.browser to kotlinx.dom and kotlinx.browser). Otherwise, the API of the library has not changed.

Other changes:

  • Added
    • in-place reversing and sorting for MutableLists and Arrays
    • naturalOrder and reverseOrder comparators
    • mapNotNull, mapIndexedNotNull, filterIndexed
    • String.toByte()
  • Deprecated (run Code Cleanup to migrate your code)
    • Function.toGenerator
    • toLinkedList
  • Dropped
    • join, merge
    • Delegates.lazy
    • FileTreeWalk.filter, File.recurse, BufferedReader.lines and lineIterator
    • assert, check and require with non-lazy message argument

Dokka

Dokka, the new documentation generation tool for Kotlin projects, has finally reached a full release. Dokka supports mixed-language projects and understands KDoc comments in Kotlin code and JavaDoc comments in Java code. Dokka has plugins for Gradle, Maven and Ant, so you can easily integrate it with the build system of your project. Download Dokka and find more information on the Dokka project site.

IDE changes

  • Completion now works for Java static members and members of objects. Just press Ctrl+Space for the second time:

  • Completion inside string templates has been added. For using it type "$name."

  • Now we can choose exact position of a breakpoint while debugging expressions with lambdas:

  • And finally, a bunch of intention actions have been added for importing Java statics, object members and enum entries. And there is an analogous one to *-import static members from Java classes or entries from enum classes

Installation

IntelliJ IDEA 15 and Android Studio will suggest you to update Kotlin automatically. If this does not happen, you can do it manually through Plugin Manager.

image description