David Smith
06/14/2021, 11:00 AMsealed class Parent() {
data class Child(val value: String) : Parent()
}
data class Other(val value: (Parent) -> String)
val child = Child("something")
val f: (Child) -> String = { child -> child.value}
val x = Other(f as (Parent) -> String)
diesieben07
06/14/2021, 11:01 AMChild
. You are casting it to something that expects a Parent
, so someone could pass in an Other
to your casted function - which would make that casted function fail.David Smith
06/14/2021, 11:02 AMDavid Smith
06/14/2021, 11:02 AMdiesieben07
06/14/2021, 11:03 AMParent
had more than one child:
x.value(Parent.Child2())
Now the function fails, because it assumes it gets a Child
, not a Child2
David Smith
06/14/2021, 11:03 AMDavid Smith
06/14/2021, 11:03 AMdiesieben07
06/14/2021, 11:04 AMDavid Smith
06/14/2021, 11:04 AMDavid Smith
06/14/2021, 11:04 AM