I've got another question related to the above example. I have a sealed class, and both implementations contain the 'same' field. So I want a function on the abstract type to retrieve it.
Copy code
sealed class Resolvable<T> {
/** There's a value in either case.
*/
fun unwrap(): T = when (this) {
is Resolved -> this.value
is Unresolved -> this.value
}
fun unwrap2(): T =
if (this is Resolved<T>) {
this.value
} else if (this is Unresolved<T>) {
this.value
}
}
data class Resolved<T>(val value: T, val pk: Long) : Resolvable<T>()
data class Unresolved<T>(val value: T) : Resolvable<T>()