Is there a way to initialize a delegated property in the same line?
For instance:
Copy code
fun main() {
val test by MyCustomDelegate() = 5 //doesn't work
test = 5 //This is the current workaround
}
I don't want to change the implementation of MyCustomDelegate per se, I just want to call its setter in line.
Is that currently possible?
e
ephemient
02/19/2022, 2:46 PM
your example doesn't work because
val
can't be assigned 😅
ephemient
02/19/2022, 2:48 PM
but is this not something you can handle when initializing the delegate itself? e.g. with the standard read-write delegates such as
Copy code
Delegates.observable(initialValue) { ... }
y
Youssef Shoaib [MOD]
02/19/2022, 2:54 PM
Whoops, yeah I intended for it to be a var, and my use case is as such 🤦
I can handle it upon initialization, sure, but that requires changing how the class is defined.
Youssef Shoaib [MOD]
02/19/2022, 2:55 PM
In my case, I'm using a class that wasn't intended to be a delegate as a delegate using extension