https://kotlinlang.org logo
Title
h

Hullaballoonatic

04/11/2019, 8:01 PM
Very long shot, but is there a way to do a late delegation of this sort?
class Matrix(elements: Collection<Collection<Double>>): MutableList<Vector> by data {
    val data = ObservableList<Vector>(elements.map { it.toVector() } , ::onAdd, ::onRemove)
}
k

karelpeeters

04/11/2019, 8:01 PM
Nope, a big limitation of delegation making it nearly useless.
h

Hullaballoonatic

04/11/2019, 8:03 PM
That's a real shame, because otherwise I gotta implement every single method of
MutableList
in exactly the same way... simply directing it to perform the exact same thing on the data field...
k

karelpeeters

04/11/2019, 8:04 PM
Subscribe to https://github.com/Kotlin/KEEP/issues/155, maybe that ever gets hold.
h

Hullaballoonatic

04/11/2019, 8:04 PM
and that's just a whole lot of verbose, unhelpful code. i wonder if i can wrap it all and hide it in IDEA
thanks
k

karelpeeters

04/11/2019, 8:05 PM
A workaround could be to hide the constructor, and have a factory create the observable and pass that as a constructor parameter, then delegate to that.
h

Hullaballoonatic

04/11/2019, 8:17 PM
but i think the dilemma is that the
onAdd
and
onRemove
function definitions need to call on fields that don't exist yet. I could pass those fields into the constructor ALSO, but this feels like a snowball effect that leads to madness and confusing code.
k

karelpeeters

04/11/2019, 8:18 PM
It's definitely not going to be pretty.
h

Hullaballoonatic

04/11/2019, 8:19 PM
i think i'll just do the verbose way and stick all the overridden methods at the bottom after a comment detailing how unimportant they are.