Edit: Just got to the bottom of the article. Looks like sealed hierarchies is exactly what they explore.
Pattern Matching for Java
11–20 of 152 posts
Re: Pattern Matching for Java
#12Re: Pattern Matching for Java
#13Pattern matching is possibly one of the most under-utilized approaches that can simplify a lot of ugly/complex logic.
Re: Pattern Matching for Java
#14Really?! exprswitch?! Unreadable and long!
Re: Pattern Matching for Java
#15Pattern matching is possibly one of the most under-utilized approaches that can simplify a lot of ugly/complex logic.
On the other hand it "prettifies" bad code style - branching by dynamic casts / type comparisons.
The authors in the article even address this point, stating that some operations might make sense as instance methods if they are instrinsic to the type hierarchy, but others, especially ad-hoc queries, are extrinsic to the types and best expressed as pattern matching.
Simply calling this "bad code style" sounds a lot like a justification for only having a verbose way to use an alternative to virtual method dispatch.
Re: Pattern Matching for Java
#16Really?! exprswitch?! Unreadable and long!
Re: Pattern Matching for Java
#17Re: Pattern Matching for Java
#18 if (is String name) {
// compiler knows 'name' is String in this block
print(name);
}
else {
print("some other text");
}
Why declare a new variable? The Ceylon syntax works great with union types too.Re: Pattern Matching for Java
#191 - case classes / value classes / data classes, whatever you want to call them.
2 - match-and-bind syntax
...
11? - fancy pattern matching
This maybe says more about how much I pay attention to what's upstream in Java, but I found the fact that this is just a hypothetical proposal, in April of 2017, strangely shocking. I guess I figured it had to be on the docket for a future java version already.
Re: Pattern Matching for Java
#20FYI, I recently found out that C# can actually do multiple dispatch
https://blogs.msdn.microsoft.com/shawnhar/2011/04/05/visitor...