what am I missing?
# announcements
m
what am I missing?
ProductImpl is a data class that contains a
Copy code
val code: String
val description: String?
so why can't I delegate?
s
Maybe the
getValue(…)
is an extension function on
KProperty0
, and you’d need to
import
that
getValue
extension function….?
m
nope, we dont have extension functions on KProperty in our project
s
I mean, the kotlin stdlib has these extension functions and you’d need to import them…
m
never needed to do that and I cannot find them either way
s
Hmmmm… you’re correct, you should not need to explicitly import them. The
getValue
extension function is defined in the the
kotlin.reflect
package, in the
PropertyReferenceDelegates.kt
file in the kotlin-stdlib-common library…
(I checked on Kotlin 1.4.10….)
v
It works fine with 1.4.10, but it fails on 1.3.72
s
IIRC, the fact that you can use a KProperty as a delegate is new in Kotlin 1.4
👌 1
m
interesting, we are indeed still on 1.3
We wanted to upgrade our project to 1.4.10 anyways so I'll check if it'll break our project
otherwise thanks
t
or you could just use a normal getter, which is easier to understand for newcomers and doesn't need reflection
Copy code
override val code get() = product.code
1