```fun Message.diffUtilEquals(o: Any): Boolean { ...
# announcements
u
Copy code
fun Message.diffUtilEquals(o: Any): Boolean {
    if (o !is Message) return false
    if (id != o.id) return false
    return true
}

fun TextMessage.diffUtilEquals(o: Any): Boolean {
    if (!super.diffUtilEquals(o)) return false
    if (o !is TextMessage) return false
    if (text != o.text) return false
    return true
}
n
Is there a reason you're using extension functions instead of normal inheritance? If you own both the
Message
and
TextMessage
classes then why not use a good old fashioned
open fun
and override it
👍🏻 1
m
There is no way of overwriting an extension function, as they are statically resolved.
Copy code
open class A
class B : A()

fun A.x() = println("A")
fun B.x() = println("B")

val a: A = B()
a.x()
This prints
A
instead of
B
.
u
@nwh because its domain layer model and diffutil is ui layer, so I didnt want dirty it (nor create ui layer model)
m
https://pl.kotl.in/amql0ZACw May be the only option, if you really need it, but I would prefer writing an extra ui layer model instead of this!
u
@molikuner yea I had something like that in mind, however the overriding was supposed to share code from Message, as my Message has id, and some other fields. Yes I can workaround it via baseDiffEquals and call it manually, but then if I were to have some more inheritance, Id need to spell out all the super classes
bummer
matter of fact I do, since example of hierachy is TextMessage : ContentMessage : Message. so I need to
Copy code
fun TextMessage.diffEquals {
   messageDiffEquals
   contentMessageDiffEquals
   my fields ..
}
right?