# Strange cast errors with Kotlin 1.0.2-1 and RxKotlin 0.60.0

**URL:** <https://discuss.kotlinlang.org/t/strange-cast-errors-with-kotlin-1-0-2-1-and-rxkotlin-0-60-0/1806>\
**Category:** Support\
**Created:** [June 15, 2016, 8:59pm UTC](https://discuss.kotlinlang.org/t/strange-cast-errors-with-kotlin-1-0-2-1-and-rxkotlin-0-60-0/1806 "2016-06-15T20:59:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [June 15, 2016, 8:59pm UTC](https://discuss.kotlinlang.org/t/strange-cast-errors-with-kotlin-1-0-2-1-and-rxkotlin-0-60-0/1806/1 "2016-06-15T20:59:23Z")

</div>

In the follow code:

```
import rx.lang.kotlin.toObservable

fun main(vararg args: String) {
    val csv = listOf(
                arrayOf("key", "value1"),
                arrayOf("", "value2")
              ).toObservable()

    csv
            .reduce(listOf<Array<String>>()) { list, row ->
                println("row ${listOf(*row)}")
                if (row[0].length == 0) {
                    // java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
                    val key = list.last().get(0)
                    println("key $key")
                    row[0] = key
                }
                list.plus(row) // required cast: as List<Array<String>>
            }.forEach { println(it) }

}

```

compiler force me to cast “list.plus(row) as List\<Array\>” (inferred as List!)!) ), if I fix this error then run the application produces a ClassCastException.

How can I fix the code?

Thanks,  
Vasco

PS: build.gradle

```
apply plugin: 'kotlin'
apply plugin: 'application'

mainClassName='TestKt'

buildscript {
    ext.kotlin_version = '1.0.2-1'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile 'io.reactivex:rxkotlin:0.60.0'
}

repositories {
    mavenCentral()
}

```

---

<div class="post-metadata">

**Author:** ![paulblessing](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/paulblessing/32/1955_2.png) [@paulblessing](https://discuss.kotlinlang.org/u/paulblessing)\
**Post date:** [June 16, 2016, 3:37am UTC](https://discuss.kotlinlang.org/t/strange-cast-errors-with-kotlin-1-0-2-1-and-rxkotlin-0-60-0/1806/2 "2016-06-16T03:37:35Z")

</div>

Looks like you may have run into a flavor of [https://youtrack.jetbrains.com/issue/KT-9992](https://youtrack.jetbrains.com/issue/KT-9992) where the `list.plus(row)` call is resolving to try to add each element of the `row` array to the list rather than adding the `Array<String>` reference as a single element. Try using `list.plusElement(row)` in place of `list.plus(row)` as noted in the comments on that issue.

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [June 16, 2016, 6:16am UTC](https://discuss.kotlinlang.org/t/strange-cast-errors-with-kotlin-1-0-2-1-and-rxkotlin-0-60-0/1806/3 "2016-06-16T06:16:27Z")

</div>

Thanks for suggestion,  
I’m going to investigate later.

Vasco
