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 and List 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:

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

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 renamed to ClosedRange and its end property renamed to endInclusive
  • Progression 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:

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.

About Andrey Breslav

Andrey is the lead language designer of Kotlin at JetBrains.
This entry was posted in Releases. Bookmark the permalink.

36 Responses to Kotlin 1.0 Beta 2 is Out!

  1. Даниил Водопьян says:

    What’s with Delegates.lazy? What went wrong with it and what to use instead?

  2. Christian says:

    filterIndexed Finally!

    String.toByte() is that a typo and should by toBytes()?

  3. Niek Haarman says:

    How should we handle the ClosedRange construct with the .. operator? Typing ‘1..2’ yields a Range, which is marked as deprecated. However, the following is not allowed:

    testRange(1..2)

    fun testRange(range: ClosedRange) {
    }

    • 1..2 yields IntRange. Your example works for me:

      Please clarify your question.

  4. Christian says:

    Is there an online example of Dokka documentation?

  5. Pingback: Yested FW was updated to Kotlin Beta 2. | Yested Framework

  6. While coding android application, the following code cause error after Kotlin’s plugins were updated.
    var intent = Intent(this, BGMService::class.java)
    Error:(72, 30) None of the following functions can be called with the arguments supplied:
    public constructor Intent(packageContext: android.content.Context!, cls: java.lang.Class<*>!) defined in android.content.Intent
    public constructor Intent(action: kotlin.String!, uri: android.net.Uri!) defined in android.content.Intent

  7. Tonisi says:

    Well done team.

    Any chance Kotlin will support union types as TypeScript and Ceylon does? It’s really useful.

  8. Alexey Romanov says:

    Why are Byte and Short progressions deprecated?

  9. Pingback: Entreprenorskapital » RoboVM 1.11 released – experimental Bitcode support, iOS 9 and Kotlin!

  10. Pingback: Entreprenorskapital » RoboVM 1.11 released – experimental Bitcode support, iOS 9.1 and Kotlin!

  11. Takuya Miyamoto says:

    Android Studio 1.5 complains the following:

    12:33:45 AM Plugin Error: Kotlin threw an uncaught AssertionError. Disable Plugin
    12:33:45 AM AssertionError: Recursion detected on input: onCreate under LockBasedStorageManager@2ca87264 (org.jetbrains.kotlin.idea.caches.resolve.GlobalContextUtilsKt.withCompositeExceptionTrackerUnderSameLock(globalContextUtils.kt:27))

    • Takuya Miyamoto says:

      The stacktrace is here.

      Recursion detected on input: onCreate under LockBasedStorageManager@4d04582c (org.jetbrains.kotlin.idea.caches.resolve.GlobalContextUtilsKt.withCompositeExceptionTrackerUnderSameLock(globalContextUtils.kt:27))
      java.lang.AssertionError: Recursion detected on input: onCreate under LockBasedStorageManager@4d04582c (org.jetbrains.kotlin.idea.caches.resolve.GlobalContextUtilsKt.withCompositeExceptionTrackerUnderSameLock(globalContextUtils.kt:27))
      at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaScope.getContributedFunctions(LazyJavaScope.kt:216)
      at org.jetbrains.kotlin.resolve.jvm.kotlinSignature.SignaturesPropagationData.getSuperFunctionsForMethod(SignaturesPropagationData.java:308)
      at org.jetbrains.kotlin.resolve.jvm.kotlinSignature.SignaturesPropagationData.(SignaturesPropagationData.java:88)
      at org.jetbrains.kotlin.load.java.components.TraceBasedExternalSignatureResolver.resolvePropagatedSignature(TraceBasedExternalSignatureResolver.java:63)
      at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassMemberScope.resolveMethodSignature(LazyJavaClassMemberScope.kt:425)
      at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaScope.resolveMethodToFunctionDescriptor(LazyJavaScope.kt:123)
      at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaScope$functions$1.invoke(LazyJavaScope.kt:82)
      at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaScope$functions$1.invoke(LazyJavaScope.kt:54)
      at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:389)
      at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:453)
      at org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaScope.getContributedFunctions(LazyJavaScope.kt:216)
      at org.jetbrains.kotlin.idea.caches.resolve.JavaResolutionUtils.resolveMethod(JavaResolveExtension.kt:96)
      at org.jetbrains.kotlin.idea.caches.resolve.JavaResolutionUtils.getJavaMethodDescriptor(JavaResolveExtension.kt:43)
      at org.jetbrains.kotlin.idea.caches.resolve.JavaResolutionUtils.getJavaMethodDescriptor$default(JavaResolveExtension.kt:37)
      at org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinPropertyAccessorsReferenceSearcher.propertyName(KotlinPropertyAccessorsReferenceSearcher.kt:55)
      at org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinPropertyAccessorsReferenceSearcher.processQuery(KotlinPropertyAccessorsReferenceSearcher.kt:37)
      at org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinPropertyAccessorsReferenceSearcher.processQuery(KotlinPropertyAccessorsReferenceSearcher.kt:34)
      at com.intellij.openapi.application.QueryExecutorBase$2.run(QueryExecutorBase.java:44)
      at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:867)
      at com.intellij.openapi.application.QueryExecutorBase.execute(QueryExecutorBase.java:42)
      at com.intellij.util.ExecutorsQuery.processResults(ExecutorsQuery.java:43)
      at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:75)
      at com.intellij.util.MergeQuery.processSubQuery(MergeQuery.java:84)
      at com.intellij.util.MergeQuery.forEach(MergeQuery.java:56)
      at com.intellij.util.UniqueResultsQuery.process(UniqueResultsQuery.java:66)
      at com.intellij.util.UniqueResultsQuery.forEach(UniqueResultsQuery.java:56)
      at com.intellij.find.findUsages.JavaFindUsagesHelper.addElementUsages(JavaFindUsagesHelper.java:604)
      at com.intellij.find.findUsages.JavaFindUsagesHelper.processElementUsages(JavaFindUsagesHelper.java:139)
      at com.intellij.codeInsight.daemon.impl.UnusedSymbolUtil.processUsages(UnusedSymbolUtil.java:265)
      at com.intellij.codeInsight.daemon.impl.UnusedSymbolUtil.weAreSureThereAreNoUsages(UnusedSymbolUtil.java:168)
      at com.intellij.codeInsight.daemon.impl.UnusedSymbolUtil.isMethodReferenced(UnusedSymbolUtil.java:148)
      at com.intellij.codeInsight.daemon.impl.analysis.PostHighlightingVisitor.processMethod(PostHighlightingVisitor.java:440)
      at com.intellij.codeInsight.daemon.impl.analysis.PostHighlightingVisitor.processIdentifier(PostHighlightingVisitor.java:262)
      at com.intellij.codeInsight.daemon.impl.analysis.PostHighlightingVisitor.collectHighlights(PostHighlightingVisitor.java:199)
      at com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl$3.run(HighlightVisitorImpl.java:184)
      at com.intellij.codeInsight.daemon.impl.analysis.RefCountHolder.analyze(RefCountHolder.java:308)
      at com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.analyze(HighlightVisitorImpl.java:177)
      at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:297)
      at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.access$200(GeneralHighlightingPass.java:64)
      at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$4.run(GeneralHighlightingPass.java:300)
      at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.analyze(DefaultHighlightVisitor.java:86)
      at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:297)
      at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectHighlights(GeneralHighlightingPass.java:266)
      at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectInformationWithProgress(GeneralHighlightingPass.java:205)
      at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:97)
      at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:67)
      at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1$1.run(PassExecutorService.java:444)
      at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1103)
      at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1.run(PassExecutorService.java:435)
      at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
      at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
      at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
      at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:432)
      at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:408)
      at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask.exec(JobLauncherImpl.java:189)
      at jsr166e.ForkJoinTask.doExec(ForkJoinTask.java:260)
      at jsr166e.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:858)
      at jsr166e.ForkJoinPool.scan(ForkJoinPool.java:1687)
      at jsr166e.ForkJoinPool.runWorker(ForkJoinPool.java:1642)
      at jsr166e.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:109)

    • Please submit bug reports to the issue tracker: https://youtrack.jetbrains.com/issues/KT

  12. Agustin says:

    Well done!.

    Would be possible to add preprocessor conditional compilation? Like C++ #ifdef would be awesome!.

    • What is your use case for #ifdef?

      • Agustin says:

        I’m writting an agnostic OpenGL engine (using Kotlin) and i was thinking on doing something like this:

        public class enum Attribute
        {
        // Desktop.
        #ifdef TARGET_OPENGL
        HALF_FLOAT = GL_HALF_FLOAT

        #else defined(TARGET_OPENGL_ES)
        HALF_FLOAT = GL_HALF_FLOAT_OES

        #else defined (TARGET_WEBGL)
        #endif
        }

        • Kotlin enums do not support things like HALF_FLOAT = GL_HALF_FLOAT, but you can use simple val‘s for that.

          • Agustin says:

            I actually wrote the example wrong.

            public class enum Attribute(public val eID)
            {
            #ifdef TARGET_OPENGL
            HALF_FLOAT(GL.GL_HALF_FLOAT)
            #elseif defined(TARGET_OPENGLES)
            HALF_FLOAT(GL.GL_HALF_FLOAT_OES)
            #endif
            }

            • Ok, now I see, thanks.

            • You can do this without #ifdef. Let’s say that TARGET_OPENGL is a simple boolean constant, then we can say

              The only thing that can not be done this way is adding/removing a constant depending on a condition

Comments are closed.