Is it possible to have a reified T for this operat...
# getting-started
g
Is it possible to have a reified T for this operator fun ? Or to know the T class at runtime ?
Copy code
operator fun getValue(thisRef: Any?, property: KProperty<T>): T {
e
an extension fun should work
g
I’m in a delegated property, can you make extension fun with the operator keyword ?
e
yes
g
What would you extend ? Thanks for the idea but I’m not sure how to put it
e
an example: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/get-value.html which allows you to write
val foo by ::bar
because
::bar
is a
KProperty
that is the receiver
g
I see, I give a whole class tho “var foo: MyObject by MongoField” with a couple more operators inside and it looks like I can’t have the extension fun one inside
“Property delegate must have a ‘setValue(User, KProperty*>, *)’ method. None of the following functions are suitable.”
t
Also you can create delegate in
inline
method
Copy code
val a by myDelegate<String>()

inline fun <reified ...> myDelegate(): ReadOnlyProperty<..., T> = MyDelegate(T::class)
🙌 1
1
🙌 1
1