Search code examples
collectionskotlinkotlin-extension

Kotlins extension method Stream.toList() is missing


I'm trying to convert a stream to a correctly typed list in kotlin. For this case kotlin provides the extension method Stream.toList(). This method is located in kotlin.streams. The IDE (IntelliJ) does not allow to call this method on a stream. Do I have to add a special dependency or should it be part of the standard library? I'm using maven and there is a dependency to kotlin-stdlib-jdk8 1.2.10.

Note: The stream is returned from a library function so I have to work with it. Please no answers like "in kotlin you do not use streams...".


Solution

  • I can reproduce your issue if I'm using the kotlin-stdlib-jdk8 dependency instead of kotlin-stdlib-jre8 (which we're not supposed to be using from 1.2 and up).

    It does, however, work if I manually add the import:

    import kotlin.streams.toList
    

    Also make sure that you've updated your Kotlin plugin to the latest version, it might also help. There's definitely something wrong with the import not being found automatically though.