# Destructuring in when

**URL:** <https://discuss.kotlinlang.org/t/destructuring-in-when/2391>\
**Category:** Language Design\
**Created:** [March 14, 2017, 10:59am UTC](https://discuss.kotlinlang.org/t/destructuring-in-when/2391 "2017-03-14T10:59:52Z")\
**Posts on this page:** 1\
**Showing post:** 25

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [November 24, 2020, 12:49pm UTC](https://discuss.kotlinlang.org/t/destructuring-in-when/2391/25 "2020-11-24T12:49:12Z")

</div>

> [@christophels](#):
>
> How can compiler deal with classes like
> 
> ```auto
> class MixedPair constructor(x1 : String, x2 : String) {
> val x = x1 + x2
> }
> 
> ```
> 
> or is it reserved to data class ?

Destructuring in kotlin is done using the `componentN` functions marked with the `operator` keyword. You can define them for any class starting with `component1`. Data classes automatically generate them.  
[https://kotlinlang.org/docs/reference/multi-declarations.html#destructuring-declarations](https://kotlinlang.org/docs/reference/multi-declarations.html#destructuring-declarations)

---

_[View the full topic](https://discuss.kotlinlang.org/t/destructuring-in-when/2391)._
