Stefan Beyer
06/06/2019, 11:52 AM// java
package com.example.legacy
public class Thing {
public String get(String s) {
return s;
}
}
// kotlin
package com.example.extensions
import com.example.legacy.Thing
operator fun Thing.get(index: Int) = index
// kotlin
package com.example.business.logic
import com.example.legacy.Thing
fun doStuff(thing: Thing) {
val x = thing[1] // compiler says "String expected, but Int found"
}
At val x = thing[1]
there is a compile error, because the extension in com.example.extensions
is not yet imported. But I cannot conveniently import it...
When I instead write it as a method call (val x = thing.get(1)
) it tells me that it can import it and I can just hit Alt+Enter and the import is added. Then I can change it back to the array access syntax.
is there a shorter and more convenient way to get this import line added?kralli
06/06/2019, 12:13 PMStefan Beyer
06/06/2019, 4:05 PM