Scott Christopher
11/04/2021, 10:31 PMScott Christopher
11/04/2021, 11:34 PMpackage a
sealed interface OldEnough
private object OldEnoughInstance : OldEnough
package b
sealed interface Employed
private data class EmployedInstance(private val proof: a.OldEnough)
: Employed, a.OldEnough by proof
ephemient
11/05/2021, 3:44 AMfun f(x: OldEnough) = when (x) {
is OldEnoughInstance -> {}
}
is allowed to assume that the only immediate subtypes of sealed OldEnough
are defined in the same package+compilation unit, and would break on f(EmployedInstance(...))
because it is notephemient
11/05/2021, 3:48 AMsealed
, or perhaps
interface HasOldEnoughProof {
val oldEnough: OldEnough
}
sealed interface OldEnough : HasOldEnoughProof {
override val oldEnough: OldEnough
get() = this
}
class EmployedInstance(override val oldEnough: OldEnough) : HasOldEnoughProof
but you haven't explained enough here to determine what is necessaryScott Christopher
11/05/2021, 4:05 AMfun <A> foo(proof: A)
where A : SomeConstraint,
A : SomeOtherConstraint = ...
Youssef Shoaib [MOD]
12/12/2021, 3:37 PMpackage a
sealed interface OldEnough
private object OldEnoughInstance : OldEnough
class OldEnoughDependent(oldEnoughInstance: OldEnough): OldEnough by oldEnoughInstance
// Other module
package b
sealed interface Employed
private data class EmployedInstance(private val proof: a.OldEnough)
: a.OldEnoughDependent(proof), Employed
Same thing can be done with an interface but I think you'll need to delegate each method manually, but AFAIK Intellij can auto-generate that