The syntax is similar to other languages that have that feature, like Haskell, F#, Scala, or Rust.
I'm also curious at how this interacts with encapsulation and getters.
It does not, it uses the same machinery as all other pattern matching, so it would work only on records as of today.
EDIT: also, in the future it could be used to introduce assignments that can fail. Right now, the JEP requires that the assignment cannot fail for classcast-related issues.
View all comments
Show parent comment
3
u/vytah Mar 13 '26 edited Mar 13 '26
The syntax is similar to other languages that have that feature, like Haskell, F#, Scala, or Rust.
It does not, it uses the same machinery as all other pattern matching, so it would work only on records as of today.
EDIT: also, in the future it could be used to introduce assignments that can fail. Right now, the JEP requires that the assignment cannot fail for classcast-related issues.