# "Extract property" in Kotlin don't work as expected

**URL:** <https://discuss.kotlinlang.org/t/extract-property-in-kotlin-dont-work-as-expected/10458>\
**Category:** Support\
**Created:** [November 21, 2018, 3:26pm UTC](https://discuss.kotlinlang.org/t/extract-property-in-kotlin-dont-work-as-expected/10458 "2018-11-21T15:26:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xloger](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/xloger/32/5796_2.png) [@xloger](https://discuss.kotlinlang.org/u/xloger)\
**Post date:** [November 21, 2018, 3:26pm UTC](https://discuss.kotlinlang.org/t/extract-property-in-kotlin-dont-work-as-expected/10458/1 "2018-11-21T15:26:46Z")

</div>

I often use “Extract Field” ([Extract field | IntelliJ&nbsp;IDEA](https://www.jetbrains.com/help/idea/extract-field.html)) to declare member variable in Java, but this is not work in Kotlin as expected:

Before:

```nohighlight
class Class {
  fun method() {
    val a = 1
    val b = 2
    var c = a + b
  }
}

```

When I select “c” and “Extract Field”, IDEA prompts “cannot introduce property for this expression”. I assumed it should goes:

```kotlin
class Class {
  var c1: String? = null
  lateinit var c2: String
  var c3 by Delegates.notNull&lt;String&gt;()

  fun method() {
    val a = "a"
    val b = "b"
    c1 = "$a $b"
    c2 = "$a $b"
    c3 = "$a $b"
 }
}

```

Is there any way to introduce an expression to a member variable using a built-in refactor function provided by IDEA when using Kotlin as language?

I asked questions at IDEA Forum([https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001708260--Extract-Field-in-Kotlin-don-t-work-as-expected](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001708260--Extract-Field-in-Kotlin-don-t-work-as-expected)) before.They say the mentioned feature in IDEA editor is a Kotlin-specific and is provided by the Kotlin plugin.So I want to know whether this is an unfinished task or a feature？

---

<div class="post-metadata">

**Author:** ![andreartus](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/andreartus/32/5754_2.png) [@andreartus](https://discuss.kotlinlang.org/u/andreartus)\
**Post date:** [November 22, 2018, 5:14am UTC](https://discuss.kotlinlang.org/t/extract-property-in-kotlin-dont-work-as-expected/10458/2 "2018-11-22T05:14:15Z")

</div>

This is interesting. When I do the normal Ctrl+Alt+F thing it does what you describe. When I remove var, and Alt+Enter on `c` then I get the option to create the property, and it works.

---

<div class="post-metadata">

**Author:** ![andreartus](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/andreartus/32/5754_2.png) [@andreartus](https://discuss.kotlinlang.org/u/andreartus)\
**Post date:** [November 22, 2018, 5:17am UTC](https://discuss.kotlinlang.org/t/extract-property-in-kotlin-dont-work-as-expected/10458/3 "2018-11-22T05:17:32Z")

</div>

If I select the expression and try “Extract Property” it creates a local value/variable. Perhaps this should go on YouTrack?

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [November 22, 2018, 12:41pm UTC](https://discuss.kotlinlang.org/t/extract-property-in-kotlin-dont-work-as-expected/10458/4 "2018-11-22T12:41:52Z")

</div>

> [@xloger](#):
>
> When I select “c” and “Extract Field”, IDEA prompts “cannot introduce property for this expression”

This is a known issue, please vote for [https://youtrack.jetbrains.com/issue/KT-11672](https://youtrack.jetbrains.com/issue/KT-11672)
