3 ms·
Does the "pattern matching" referred to here work like JavaScript's "destructuring?" It's the thing where you can call a function with an object, but the functi
by ShadowBanThis01 3y ago
Does the "pattern matching" referred to here work like JavaScript's "destructuring?" It's the thing where you can call a function with an object, but the function's parameters extract one or more of the object's members directly without mentioning the object's class, so it'll take anything that has appropriately named members.
- nsonha 3y agono, pattern matching is more like destructuring AS CONDITIONS (eg: if object has this structure) of switch blocks. While destructuring is simply sugar for assignment, pattern matching is more complex. I don't know about Java but in some languages you can customize the pattern so that it is not neccessarily in the actual shape of the object. In some languages applying pattern matching at the top level of the function is the equivalence of overloading.
- ShadowBanThis01 3y agoThanks! Intuitively this sounds like it enables what at one time would have been called bad programming (widespread reliance on RTTI), but on the other hand a lot of rules have turned out to be arbitrary.
- DeathArrow 3y agoI think they've partly implemented C# version of pattern matching.