# Multiple assignment?

**URL:** <https://discuss.kotlinlang.org/t/multiple-assignment/69>\
**Category:** Uncategorized\
**Created:** [October 15, 2015, 5:08pm UTC](https://discuss.kotlinlang.org/t/multiple-assignment/69 "2015-10-15T17:08:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rnikander](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/rnikander/32/6881_2.png) [@rnikander](https://discuss.kotlinlang.org/u/rnikander)\
**Post date:** [October 15, 2015, 5:08pm UTC](https://discuss.kotlinlang.org/t/multiple-assignment/69/1 "2015-10-15T17:08:59Z")

</div>

I see I can do this:

&nbsp;&nbsp;val (a, b) = getThingWithTwoParts()

but not, it seems, this…

&nbsp;&nbsp;var a = …  
 &nbsp;&nbsp;var b = …  
 &nbsp;&nbsp;(a, b) = getThingWithTwoParts()

Is that right?

thanks,  
Rob

---

<div class="post-metadata">

**Author:** ![cedricbeust](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/cedricbeust/32/1429_2.png) [@cedricbeust](https://discuss.kotlinlang.org/u/cedricbeust)\
**Post date:** [October 15, 2015, 10:51pm UTC](https://discuss.kotlinlang.org/t/multiple-assignment/69/2 "2015-10-15T22:51:56Z")

</div>

This only works with data classes:

&nbsp;

```kotlin
data class Foo(val a: Int, val b: String)
val (c, d) = Foo(1729, "Hi")
```

---

<div class="post-metadata">

**Author:** ![rnikander](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/rnikander/32/6881_2.png) [@rnikander](https://discuss.kotlinlang.org/u/rnikander)\
**Post date:** [October 16, 2015, 1:04am UTC](https://discuss.kotlinlang.org/t/multiple-assignment/69/3 "2015-10-16T01:04:52Z")

</div>

But there's no way to re-assign to vars like that, correct?

Rob

---

<div class="post-metadata">

**Author:** ![mplatvoet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mplatvoet/32/7121_2.png) [@mplatvoet](https://discuss.kotlinlang.org/u/mplatvoet)\
**Post date:** [October 17, 2015, 12:35pm UTC](https://discuss.kotlinlang.org/t/multiple-assignment/69/4 "2015-10-17T12:35:45Z")

</div>

Not at the moment no, but I thought there where plans after 1.0 for expanding the possibilities, Probably someone from JetBrains can answer that. There are also wishes to ignore values. I think we can expect '\_' for that.

The only requirement is not data classes by the way, but having componentN&nbsp;&nbsp;methods, e.g.

```kotlin
fun main(args: Array<String>) {
    val (a, b) = Foo("Hello", "world")
    println("$a, $b!")
}

class Foo<A, B>(val a: A, val b : B) {
  fun component1() : A = a
  fun component2() : B = b
}
```
