I often use “Extract Field” (Extract field | IntelliJ IDEA) to declare member variable in Java, but this is not work in Kotlin as expected:
Before:
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:
class Class {
var c1: String? = null
lateinit var c2: String
var c3 by Delegates.notNull<String>()
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) 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?