raulraja
11/03/2019, 11:33 PMtschuchort
11/04/2019, 11:07 AMUnion<A,B>
be a subtype of Union<B,A>
?raulraja
11/04/2019, 12:33 PMtschuchort
11/04/2019, 3:44 PMUnion<A,B>
and Union<A,B,C>
? Any function that accepts Union<A,B,C>
should also accept Union<A,B>
.tschuchort
11/04/2019, 3:47 PMObject
and check types in the kotlin compiler, but it would cost you type-safety on the Java side if that's something you care about.raulraja
11/04/2019, 6:06 PMraulraja
11/04/2019, 6:06 PMinterface Union2<out A, out B>
interface Union3<out A, out B, out C> : Union2<A, B>
interface Union4<out A, out B, out C, out D> : Union3<A, B, C>
raulraja
11/04/2019, 6:07 PMraulraja
11/04/2019, 6:08 PMinline class Union(val value: Any?) :
Union2<Nothing, Nothing>,
Union3<Nothing, Nothing, Nothing>,
Union4<Nothing, Nothing, Nothing, Nothing> {
inline operator fun <reified A> invoke(): A? =
value as? A
companion object {
inline fun <reified A> union(union: Union): A? =
value as? A
}
}