Very long shot, but is there a way to do a late de...
# announcements
h
Very long shot, but is there a way to do a late delegation of this sort?
Copy code
class Matrix(elements: Collection<Collection<Double>>): MutableList<Vector> by data {
    val data = ObservableList<Vector>(elements.map { it.toVector() } , ::onAdd, ::onRemove)
}
k
Nope, a big limitation of delegation making it nearly useless.
h
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
Subscribe to https://github.com/Kotlin/KEEP/issues/155, maybe that ever gets hold.
h
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
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
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
It's definitely not going to be pretty.
h
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.