https://kotlinlang.org logo
#announcements
Title
# announcements
i

ikozlowski

10/26/2019, 4:39 PM
I'm trying to write extension for AssertK that will deep compare objects ignoring id. Works well if I use
T:Any
but fails when I want to support nullable fields. Any idea how to cast other to not null type so I can access it class.members?
Copy code
fun <T : Any?> assertk.Assert<T>.isEqualToIgnoringId(
    other: T
) {
    all {
        if (other == null)
            this.isEqualTo(null)
        else
            other?.let { it::class.members }
    }
}
k

Kroppeb

10/26/2019, 5:01 PM
What if you make
T
extend
Any
and then use
Assert<T?>
and
other:T?
?
i

ikozlowski

10/26/2019, 5:18 PM
worked, thanks 🙂
27 Views