https://kotlinlang.org logo
#android
Title
# android
m

Mark

05/17/2020, 4:07 AM
In Android Studio, is there a quick way to convert a function to a property (and all usages, of course): e.g.
fun length(): Int
to
val length: Int
?
j

jw

05/17/2020, 4:17 AM
Add the property, change the function to
fun length() = length
, inline function
👍 4
m

Mark

05/17/2020, 4:28 AM
I’m not sure that will work in my case since
length()
is an interface function and so is overriden in many places. I’m introducing an interface in the interface hierarchy that comes with
val length: Int
so I guess that means
override val length get() = length()
at that point, but I really don’t like all those doubled-up
length
code completions
d

Dominaezzz

05/17/2020, 4:37 AM
Ctrl+Alt+F
r

rax

05/17/2020, 11:15 AM
1. Add the property in your interface. This will take care of your interface implementations. 2. mark the function as deprecated with error level and add ReplaceWith to replace with the property. This will show you compiler errors around the usage of the deprecated function with an easy way to replace usage.
👍 1
u

ursus

05/18/2020, 5:14 AM
ctrl+shift+r
2 Views