On a tangent, how do you do sum types in java? I recently wanted to use them and all I could figure out was some subclasses and `instanceof` as poor man's pattern matching.
That's how. Sum types were largely dropped from imperative languages in favor of subclassing during the OO craze (which is why they had to be re-discovered from the functional world).
Look up sealed classes if you're using Java 15. There's no proper exhaustive pattern matching for them yet though, but that's coming in a future version.