Live data from Hacker News

Pattern Matching for Java

cr.openjdk.java.net

1–10 of 152 posts

Re: Pattern Matching for Java

#3
post #2

Really great proposal. Is this conversation in relation to Java 10 or just pie in the sky?

This is an exploratory document only and does not constitute a plan for any specific feature in any specific version of the Java Language.

I hope it does go forward, though. Really useful feature, and given the constraints of the existing language, the proposed syntax looks pretty liveable-with.

Re: Pattern Matching for Java

#4
Any substantial differences from Scala's implementation? From what I remember of Odersky's book it seems very similar if not identical. (Which is fine - I'm all for Java incorporating the best parts of Scala.)

Re: Pattern Matching for Java

#7
"How we declare the destructuring pattern in the AddNode class, or declare AddNode so that it implicitly acquires one, will be covered in a separate document."

Please use a Scala unapply() and not just constructor parameters. The former gives much more latitude to build patterns.

I have a ton more to say about all of this having written in Scala and Kotlin extensively. I'll just say that it is useful they are already thinking about new variable assignment to parts of matches and NOT concerning themselves w/ "smart casts".

Re: Pattern Matching for Java

#8
post #4

Any substantial differences from Scala's implementation? From what I remember of Odersky's book it seems very similar if not identical. (Which is fine - I'm all for Java incorporating the best parts of Scala.)

The syntax looks similar, but there's no mention of an `unapply()`-type thing, which would limit the flexibility of this proposal greatly.

Re: Pattern Matching for Java

#9
I really really like these suggestions. Especially the first parts where I have found myself writing a lot of instance-of-cast and just marvel at how much clutter it actually adds without adding more description to the code. I do also ponder if there is a limit to how much we should potentially shorten the expressions, not to make the expressions extremely dense it understanding. The last opinion is just taste though, admittedly.
Post reply on HN