Java 21 💣💥 By Nicolai Parlog
Вставка
- Опубліковано 21 сер 2024
- Java 21 is an explosive release!
The fuse was lit by projects Loom and Amber and 21 blows it up by finalizing virtual threads and all basic building blocks of pattern matching, thus bringing simple scalability to the platform and modern constructs to the language.
But it doesn't stop there: better APIs, better garbage collection, better tooling - particularly when you're coming from 17, the improvements will be ubiquitous.
And beyond all that, Java 21 is fizzling with future:
There are previews on string templates
a simplified `main`,
pattern matching refinements
improved concurrency with virtual threads
Not least, many vendors offer long-term support for their JDK 21 builds, so if you're on 17 or 11 (or 8?), this is the next version to upgrade to.
In this talk, we'll go over all that, so you can hit the ground running when updating to Java 21
Disclaimer: It will be a blast! 💥
NICOLAI PARLOG
Nicolai (aka nipafx) is a Java enthusiast focused on language features and core APIs with a passion for learning and sharing - in articles, newsletters, and books; in tweets, videos, and streams; in demo repos and at conferences - more on all of that on nipafx.dev. He's a Java Developer Advocate at Oracle and organizer of Accento. That aside, he's best known for his haircut.
very interesting, thank you🙂
1:17:55 on my machine the first run takes 3.5s (excluding compilation, just the loop), but subsequent runs take less than 2s.
inet resolvers
@9:30 As a user, LTS is the assurity that the version is solid and one need not to worry about short-comings or a major bug, because its owner's word. Even if you don't use Oracle JDK,
You just took that confidence out.
That's not what LTS ever meant. Just that it will get updates for a long time. No GA java version has any major bugs or shortcomings.
sealed interface... permits.... that really seems like a dumb feature. Who can give real practical examples why anybody should want this!?
This allows you to expose your internal hierarchy but still disallowing others to hijack it by overwriting its behaviour. This feature is a great tool for framework developers.
The Class now also got a new method "getPermittedSubclasses". Here an example:
Map
@@konstantinatwork3105 Ok, maybe nice for frameworks. The code example looks like nothing i would ever want to write. Our production code is not allowed to use reflection and this whole sealed/permit stuff seems like something that only a minority ever wanted or needed. It actually still seems like a huge anti pattern to me. Still not impressed by Java 21 atm. I think looking at golang, typescript and rust on the server side: Java is steadily losing ground. It really feels more and more like COBOL. I still love Java, have done most of my code with it, but i feel more and more like the language does only fix it's own problems. Looking at these string templates STR. ..... really? That is the best they came up with? It feels so clunky. Well it will motivate me more and more to look at alternatives.
sealed interface allow java to have something similar to rust tagged union
Example use case: Polymorphic return types. I once wrote a method that could return either type A or B depending on the outcome. I wrote an "Either" class for that with Optional like methods ("ifLeft(Consumer), ifRight(Consumer)"). Today I would use a sealed interface for that and apply a switch expression to the return value, which ensures at compile time that I cover both cases. If the return type can't implement the interface, then I'd use a record wrapper around the value and use pattern matching to extract the original one.
@@hariseldon02 thanks i actually did not think about that. Still feels a little clumsy but might come in handy 🖖👍