In Android Studio, is there a quick way to convert...
# android
m
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
Add the property, change the function to
fun length() = length
, inline function
👍 4
m
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
Ctrl+Alt+F
r
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
ctrl+shift+r