Say I have a Foo class with bar() method, and several classes, A, B, C, whose companion inherits from Foo. Now, I have a variable, x, and I know it is of type A, B or C (but not exactly which one). I would like to call bar() from x’s companion. How would I do this?
I tried x.bar() (which would be ideal for me) and x.Companion.bar() and neither compile.What’s the idiomatic way to do this?
Note: I’m aware I could do a switch so if x is A then A.bar(), etc, but that’s highly unpractical.