[flagged]
What is the "cool" language nowadays?
Java 20 / JDK 20: General Availability
31–40 of 356 posts
Re: Java 20 / JDK 20: General Availability
#32This 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()…
At 3rd preview, they switched to when: https://openjdk.org/jeps/427
In that JEP they state:
> Based upon experience and feedback we propose instead to allow when clauses in switch blocks to specify guards to pattern labels
So I assume people thought && was confusing.
Re: Java 20 / JDK 20: General Availability
#33Java 8 is the best Java.
Re: Java 20 / JDK 20: General Availability
#34This 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()…
The “if” one does not suffer from any such problem and reads okay to me. I guess one argument against it could be that since the whole thing is a distinct grammatical construct, why not just introduce a distinct keyword instead of making an existing keyword depending on context? That’s mostly a question of style though (e.g. I don’t know right now if Java already has an habit of reusing keywords like that).
Re: Java 20 / JDK 20: General Availability
#35This feels a bit like discussing the new fancy garden hoe as a farm hand as they are making the tractor.
Re: Java 20 / JDK 20: General Availability
#36Re: Java 20 / JDK 20: General Availability
#37Does anyone know the solution?
Re: Java 20 / JDK 20: General Availability
#38This 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…
Re: Java 20 / JDK 20: General Availability
#39This 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 2nd preview, they used &&: https://openjdk.org/jeps/420 At 3rd preview, they switched to when: https://openjdk.org/jeps/427 In that JEP they state: > Based upon experience and feedback we propose instead to allow when clauses in switch blocks to specify guards to pattern labels So I assume people thought && was confusing.
Re: Java 20 / JDK 20: General Availability
#40This seems like an appropriate place to post the official Java rap: https://youtu.be/b-Cr0EWwaTk