Live data from Hacker News

Java 20 / JDK 20: General Availability

mail.openjdk.org

21–30 of 356 posts

Re: Java 20 / JDK 20: General Availability

#28

This is exciting, can't wait for the LTS release next year... that said, I don't much care for the "case SomeType t when ..." pattern matching syntax, I don't see the benefit of introducing a new keyword over using "if"... or even just "&&". To pinch the example used in[1]: case Tuner t && guitar.isInTune() -> ...; and case Tuner t if guitar.isInTune() -> ...; both seem as clear as case Tuner t when guitar.isInTune()…

In the case of &&, the left hand side of the expression (Tuner t) isn't a boolean expression.

In the case of "if", you're right, the grammar doesn't work, both because the syntax of Java already says that the if condition must be enclosed in parentheses and also because an if block is a statement and you need an expression here.

To make either of those work, you'd have to make the rest of the pattern matching syntax much worse.

Re: Java 20 / JDK 20: General Availability

#29
post #26

Now even Java has pattern matching, what's Javascript's excuse? Literally the only feature preventing Typescript from being my perfect language.

https://github.com/tc39/proposal-pattern-matching

I'm not sure if it's stalled or not. But it's being discussed.

Re: Java 20 / JDK 20: General Availability

#30

This is exciting, can't wait for the LTS release next year... that said, I don't much care for the "case SomeType t when ..." pattern matching syntax, I don't see the benefit of introducing a new keyword over using "if"... or even just "&&". To pinch the example used in[1]: case Tuner t && guitar.isInTune() -> ...; and case Tuner t if guitar.isInTune() -> ...; both seem as clear as case Tuner t when guitar.isInTune()…

they want it to be as ugly as cpp
Post reply on HN