|
|
|
|
|
by quilombodigital
1504 days ago
|
|
"If in your career you never needed to enumerate cases that required different data..." . Maybe one or two times... but it is not like "hey, it is impossible", or "shit, I have to write 10 more lines" in this rare code I will never put my eyes again. What I get angry is that people will start to use everywhere, in places they should not be using. because the guy did not wanted to stop five minutes to think about it. The river flows through the easiest path, but this does not means it is the smartest path. |
|
It's fair that you've found sensible ways to achieve your goals without ever needing pattern matching. Nobody should fault you for that. But can you grant that other developers might have other sensible ways to achieve other goals (or sometimes other ways to achieve the same goals!)?
I think most Java developers will be familiar with the visitor pattern. In almost all cases (there are exceptions!), I detest it; I find sum types with pattern matching to be a far superior way to say what I mean. Java added `sealed` interfaces recently, so you can actually model a closed family of types. Now pattern matching closes the loop, giving you a supremely ergonomic way of dispatching over that closed family without using a visitor.
Maybe it's not clear from other responses, but the part of the JEP about an "exhaustive switch" is critical here. Java statically guarantees that you've handled each member of your closed family, just like if you forgot to implement a method for a visitor.