Apparently Java still won't have algebraic data types, which are very useful for this kind of code. It does have records, which are like kotlin data classes, a slightly more compact switch statement, and "pattern matching" which isn't actually pattern matching, it just allows you to omit a cast in an if branch if the if condition checks the type using instanceof.