Considering Help reduce code with kotlin idiom :
It is an example where developer has no control on classes implementation and pass Any then use when to switch on type… But he need a else then… #FeelsBadMan.
Union type would (actually could, depend on use of the function…) fix the else problem.
That’s been said the when still feels bad: the repeat again and again… the perfect solution would be to find a way to implement a “trait” (ideally an interface, but I don’t think it would technically be possible on jvm). Something like in rust… (I admit this is a part I love about rust). This would make the union type obsolete and would be very more powerful.