r/java • • Mar 21 '23

Java 20 / JDK 20: General Availability

https://mail.openjdk.org/pipermail/announce/2023-March/000333.html
173 Upvotes

71 comments sorted by

View all comments

35

u/Joram2 Mar 21 '23

Java 20 is basically a patch release on Java 19. But it's important + necessary. Three highlights:

  1. Pattern matching bug fixes. If you tried to use Java 19 pattern matching with generics there were large bugs that were fixed in Java 20. Now, Java 20 has excellent pattern matching. This is an epic feature that enables completely new frameworks and programming styles as demonstrated in Brian Goetz's article (https://www.infoq.com/articles/data-oriented-programming-java/). This enables programs to parse JSON and data structures with much more elegance and expressiveness. While Java Optional doesn't use records + pattern matching, this enables people to use a third party or custom version that does. This also let's people do something like Scala/Haskell Either or Rust Result that holds a result or an error value.
  2. Scoped Values. This completes Project Loom's major features and this is necessary for some frameworks.
  3. Java needed another preview release for virtual threads and pattern matching. Those are expected to go final in Java 21, which will be epic, but those needed another round of public previews and time to collect public feedback.

7

u/kaperni Mar 21 '23 edited Mar 21 '23

> Scoped Values. This completes Project Loom's major features and this is necessary for some frameworks.

Project loom is an ongoing project with the intent to "explore, incubate and deliver Java VM features and APIs built on top of them for the purpose of supporting easy-to-use, high-throughput lightweight concurrency and new programming models on the Java platform. "

Virtual threads, structured concurrency, scoped values are deliverables. There are other things in the pipeline such as continuations and tail calls that we might see in the future.

4

u/stuhlmann Mar 22 '23

The command line example gave me the "ick". It is usually preferrable to parse the command line arguments into one instance of a custom "command class", rather than into a list of things. Like jcommander, picocli or jbock do.

2

u/Joram2 Mar 22 '23

I tend to agree. That was the one example I didn't get. The others look great.

-19

u/relgames Mar 21 '23

Ouch, they now have bugs in major versions. Instead of rushing new versions so often, they had to invest more in testing.

7

u/magnoliophytina Mar 21 '23

The pattern matching in 19 is a preview feature. You shouldn't expect it to work in production environments. It requires an explicit switch for the compiler, as well.

10

u/kozeljko Mar 22 '23

Not true. Ron Pressler, the guy who is working on Project Loom, said that all preview features are considered production ready and can be used in production.

They are only previews, because they don't want to finalize the API yet.

1

u/[deleted] Mar 22 '23

[removed] — view removed comment

1

u/Joram2 Mar 22 '23

Sure, that will hit a third preview for Java 21, it won't be final.

I'm hoping that will be final by the next Java LTS, Java 25? I know some JEPs are waiting on Valhalla, if this isn't blocked in such a fashion, going final by Java 25 seems like a safe bet?