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
andFloat
progressions are droppedByte
andShort
progressions are deprecated, the..
operator for bytes and shorts now returnsIntRange
Range<T>
renamed toClosedRange<T>
and itsend
property renamed toendInclusive
Progression<T>
is deprecated in favor of concrete progression implementations instead:IntProgression
,LongProrgession
,CharProgression
start
andend
properties in progressions are renamed tofirst
andlast
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
MutableList
s andArray
s naturalOrder
andreverseOrder
comparatorsmapNotNull
,mapIndexedNotNull
,filterIndexed
String.toByte()
- in-place reversing and sorting for
- Deprecated (run Code Cleanup to migrate your code)
Function.toGenerator
toLinkedList
- Dropped
join
,merge
Delegates.lazy
FileTreeWalk.filter
,File.recurse
,BufferedReader.lines
andlineIterator
assert
,check
andrequire
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
static members from Java classes or entries from enum classes*-import
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.
Даниил Водопьян says:
November 16, 2015What’s with
Delegates.lazy
? What went wrong with it and what to use instead?Roman Belov says:
November 16, 2015Simply,
lazy
https://kotlinlang.org/docs/reference/delegated-properties.html
Даниил Водопьян says:
November 16, 2015That’s cool! Wanted that for a long time!
Is
Delegates.observable()
still in stdlib, or the docs are wrong?Sergey Mashkov says:
November 16, 2015Everything is fine both with stdlib and docs: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.properties/-delegates/observable.html
Christian says:
November 16, 2015filterIndexed
Finally!String.toByte()
is that a typo and should bytoBytes()
?ilya.gorbunov says:
November 16, 2015It’s a string-to-number conversion, like
toInt()
,toDouble()
etcSergey Mashkov says:
November 16, 2015String.toByte() is a function to parse a string as a number. To get bytes you need toByteArray
Niek Haarman says:
November 17, 2015How 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) {
}
Andrey Breslav says:
November 17, 20151..2
yields IntRange. Your example works for me:Please clarify your question.
Christian says:
November 17, 2015Is there an online example of Dokka documentation?
Sergey Mashkov says:
November 17, 2015Sure. Kotlin’s API reference has been generated by Dokka: https://kotlinlang.org/api/latest/jvm/stdlib/index.html
Sergey says:
November 17, 2015On page https://kotlinlang.org/api/latest/jvm/stdlib/index.html link “kotlin” refers to a https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/index.md that is not found (404). Probably should refer to page https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/.
Karol Stasiak says:
November 17, 2015Most links go 404 for me.
Max M. says:
November 17, 2015All link currently run into a 404. Are you maybe updating ATM?
Eg: http://kotlinlang.org/api/latest/jvm/stdlib/kotlin/index.md
Andrey Breslav says:
November 17, 2015Links have been fixed. Thanks for the report
Yested FW was updated to Kotlin Beta 2. | Yested Framework says:
November 17, 2015[…] Yested FW was updated to Kotlin Beta 2. […]
changmin.jeon says:
November 17, 2015While 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
yanex says:
November 17, 2015It works for me. Can you provide some more details? Slack or email (yan.zhulanow[at]jetbrains.com) is also ok.
changmin.jeon says:
November 18, 2015It’s working. It was my mistake. sorry for confusing your team.
Tonisi says:
November 18, 2015Well done team.
Any chance Kotlin will support union types as TypeScript and Ceylon does? It’s really useful.
Andrey Breslav says:
November 18, 2015We are looking for ways of supporting something like union types for JavaScript interop
Tonisi says:
November 18, 2015That’s amazing news. Will this include flow sensitive typing?
Andrey Breslav says:
November 18, 2015Not sure. We’ll see
Alexey Romanov says:
November 20, 2015Why are
Byte
andShort
progressions deprecated?Entreprenorskapital » RoboVM 1.11 released – experimental Bitcode support, iOS 9 and Kotlin! says:
November 20, 2015[…] on the latest Kotlin Beta, you can now create cross-platform Android and iOS app in Kotlin from within RoboVM Studio or […]
Entreprenorskapital » RoboVM 1.11 released – experimental Bitcode support, iOS 9.1 and Kotlin! says:
November 20, 2015[…] on the latest Kotlin Beta, you can now create cross-platform Android and iOS app in Kotlin from within RoboVM Studio or […]
Takuya Miyamoto says:
November 21, 2015Android 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:
November 21, 2015The 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)
Andrey Breslav says:
November 21, 2015Please submit bug reports to the issue tracker: https://youtrack.jetbrains.com/issues/KT
Agustin says:
December 4, 2015Well done!.
Would be possible to add preprocessor conditional compilation? Like C++ #ifdef would be awesome!.
Andrey Breslav says:
December 4, 2015What is your use case for
#ifdef
?Agustin says:
December 5, 2015I’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
}
Andrey Breslav says:
December 7, 2015Kotlin enums do not support things like
HALF_FLOAT = GL_HALF_FLOAT
, but you can use simpleval
‘s for that.Agustin says:
December 8, 2015I 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
}
Andrey Breslav says:
December 8, 2015Ok, now I see, thanks.
Andrey Breslav says:
December 8, 2015You can do this without
#ifdef
. Let’s say thatTARGET_OPENGL
is a simple boolean constant, then we can sayThe only thing that can not be done this way is adding/removing a constant depending on a condition