@FiniteLooper instanceof nether support exhaustive check. Even if AB is a parent class (because there is no concept of sealed classes).
But now I am thinking that probably ‘switch (ab.constructor.name) {‘ would be more symmetrical to discriminated unions.