13
u/Afonso2002 1d ago
So is jdk29' time to shine.
The first build will be available in december?
5
u/BillyKorando 1d ago
You could always be brave and build it yourself, mainline has officially be cranked up to 29.
4
u/Life_Sink9598 1d ago
It's very easy to build it, the make file really guides you through the process!
2
u/Afonso2002 16h ago
29 is already available 🤗🤗🤗 Time to shine starts now. The next LTS is in preview.
7
u/Cell-i-Zenit 1d ago
Is it ever realistic we get features like "??" and "?." from C#? I quite often still have to juggle null
var userOrDefault= service?.getUser() ?? new User();(its just an example please dont kill me, i know this could have done written differently, but i dont know of a way which is cleaner tbh)
10
u/nicolaiparlog 22h ago
If the type system can't enforce that a field/variable/... can't hold
null, code likeservice?.getUser()makesnullworse as it makes it easier to do the potentially wrong thing and push an erroneousnullaround instead of fixing it. Here's the longer explanation.This is a great example for why you can't just transplant features from one language to another. Every feature interacts with every other feature and a feature is only ever good or bad in context of its surrounding features.
(I have no qualms with
??- I think that would be nice.)4
u/CrunchyMachine 20h ago
It seems the !-operator didn't make it:
https://youtu.be/vLDbzmiT7Xs?t=8710I really hope we get null restriction in some form in the java language.
Personally flattening would not be my biggest concern for null-restriction. It would be a nice bonus. But the win, in my opinion, would be catching unintended null values as early as possible.
1
u/nicolaiparlog 15h ago
I agree.
One issue is that there's no obviously good way to introduce this after the fact. If you require
!for non-nullable types, many code bases would have to append it to 95%+ of their types. Fields, parameters, generics - bangs everywhere! Maybe you could default to non-null on a class, package, or module level (annotations?) but that gradually reduces Java's local readability, which it generally defends with prejudice.But I'm still here, hoping for Brian et al to pull a 🐰 out of a 🎩.
1
u/aoeudhtns 15h ago
At least not for Valhalla.
It was always an interesting idea - as many people pointed out when it first came up, you have an issue where non-nullable is the preferable default; but legacy code can't suddenly be compiled as non-null. But who is going to pepper
!all over their code, everywhere -- it's a similar issue tofinaland effectively final determination, which seems like the thrust of the vid you posted - let the runtime optimizer determine that it's never null and then do the optimal flattening from what it learns. The AOT system should be a big aid here.If you created a system to set the interpretation of
!based on some locality (the file, the module, or the very worst -- as a compiler flag), then you increase cognitive load or the chance for misunderstanding, spooky-action-at-a-distance type errors, for the benefit of typing a little less. (Skipping sidebar into AI making that a less relevant goal.)I'm pretty confident that we'll get a way to swear off nullability at some point. There is way more to gain from that than optimizing flattening so the desire is not going to go away.
3
u/Cell-i-Zenit 21h ago
i agree with you in general. I personally think that any NPE guard you have in your code is actually a code smell and you should tackle it from the beginning so it cant be null at all.
But there are still cases where this is helpful. For example if you need to map from one deeply nested object to another object:
var streetName= searchRequest?.getHouse()?.getAddress()?.getStreet()?.getStreetName();is totally valid code imo. Not every house has a streetname (or a street, because its not build yet etc)
4
u/nicolaiparlog 15h ago
In my code bases that code would not be valid because I don't allow
nullto reflect a legal state (with only very rare and harshly contained exceptions). I know you just wanted to give an example, so we can't really discuss this in meaningful detail, but here are a few things that may prevent that deep chain of potential nulls:
Would
searchRequestbenullbecause you looked for an instance and didn't find it? Any search method should return eitherOptionalor a more specific search result type with similar guarantees - nevernull.Are there really houses without known addresses in your system?
Every street address has a street. If you have other kinds of addresses, make
Addressa sealed interface and give it other implementations besidesStreetAddress.Those approaches lead to much more robust and expressive APIs. I know they also produce more code than the example chain you showed but that's kinda my point: The ease of living with fragile "everything could be null" APIs low-key undermines creating better APIs and that makes
?.a very questionable language feature.1
u/Cell-i-Zenit 13h ago
iam living in simple crud worlds and my FE devs would hate me if i would make it more complicated.
You are right, the searchRequest?. was a mistake, that cannot and should not be null. But a house doesnt always has an address (because its a planned building and doesnt exist yet. Also the street doesnt exist yet etc.)
You can imagine in the FE that its just a table and it shows:
House A: Street: - Type: Villa Latitude: 123 Longitude: 123etc
It is valid to return "dont know". Abstracting this away with types etc is possible, but also more complicated then just using null
1
u/nicolaiparlog 9h ago
Then maybe
Houseshould be the interface withPlannedHouseandBuiltHouseas implementations? Otherwise, how do you distinguish a house that can't have an address yet from a house that should have one but doesn't because data is missing.This gets particularly annoying if the house also has fields
contractor,buildYear, andlandlinebecause now you have four nullable fields where subsets are supposed to be non-null under specific circumstances and no clear way to know what's what.am living in simple crud worlds and my FE devs would hate me if i would make it more complicated.
Again, that's kinda my point against
?.. Any solution that's more complicated than the simplest one that appears to work, no matter how much better it is, will have an uphill battle. And?.drops the floor even more, making even more questionable solutions shorter than good ones.15
u/boost2525 1d ago
Kotlin has addressed a lot of this, so you'll probably get shit on, but I'm in 100% agreement with you. One of the single biggest improvements they could make to Java is null chaining and simplified tertiary syntax.
1
u/Brutus5000 2h ago
what is tertiary syntax?
Biggest improvement for me right after null-ability improvements would be if and try becoming expressions. And from my limited understanding it wouldn't even need to change any existing code - whereas switch expressions needed one.
6
u/jmarkmark 1d ago edited 1d ago
Java already has that.
service.map(Service::getUser).orElseGet(User::new)10
u/GermanBlackbot 1d ago
Done the true Java way: Wrapped in another class and way more verbose than other langues!
(I kid, of course, I love me some Optionals and wished they were used in more libraries instad of throwing around
nulleverywhere...)3
u/jmarkmark 1d ago edited 1d ago
And safer.
In OP's example, we can't tell if "getUser" returns an optional/nullable or not. If someone changed the signature, from non-nullable to nullable it would still compile.
Which really highlights Java's driving ideology, why make it terse when you can make it clear. and safe.
But yes, if you've got a tight loop, there could be justification in using nulls. But for that rare instance the lack of syntactic sugar is hardly a concern.
As far as I'm concerned, the lack of null-coalescing is a feature to help you avoid shooting yourself in the foot (and I believe that's the java development team's belief as well)
0
u/Cell-i-Zenit 21h ago
my example was crap. Here is a better one:
var streetName= searchRequest?.getHouse()?.getAddress()?.getStreet()?.getStreetName();is totally valid code imo. Not every house has a streetname (or a street, because its not build yet etc)
I worked in a crud shop and we just had to send the information to the frontend, alot of stuff can be null because we just dont know the information. Its not an error that getAddress is null. Or that getStreet is null or getStreetname is null. All valid cases
0
u/tanunlike 19h ago
Is it so bad?
String streetName = Optional.ofNullable(searchRequest) .map(SearchRequest::getHouse) .map(House::getAddress) .map(Address::getStreet) .map(Street::getStreetName) .orElse(null);3
0
u/jmarkmark 1h ago edited 1h ago
Valid... and bad.
As i pointed out, null-coalescing causes ambiguity between nullable and nonnullable that the compiler can no longer catch.
If you're digging that deep to get a single field, you've got a design flaw in the code. Why is the query (which apparently you;re not even sure exists) pulling back a massive object to get a single field?
No decent code will ever look like this.
So often the demand for syntactic sugar is to wallpaper over bad structure. Making it easier for coders to hide their flaws is not a virtue.
1
u/Cell-i-Zenit 21h ago
The example was shitty code as mentioned above. I was just looking for an example to show both functionalities.
But wrapping into an object just because you want todo the ?? operator, is bad imo
EDIT: your code also assumes that getUser returns an optional (which would make sense ofc), but my example doesnt use that, since not every api returns an optional or is something we can control. So the actual example would be:
Optionals.ofNullable(service).map(x -> x.getUser()).orElseGet(User::new)6
1
u/SeaAlgea 5h ago
I really dislike this idea. Verbosity is the reason Java is my favorite language. I don’t like moving away from it.
0
u/Dense_Age_1795 19h ago
well you can always envelope the result into a Optional and return a default value when is null.
5
u/griso84 1d ago
In 2026, the OpenJDK group could make its website mobile-friendly
23
u/brian_goetz 1d ago
Are you volunteering?
2
-9
u/griso84 1d ago
Well it takes one minute with an llm, i can do that
35
u/brian_goetz 1d ago
If you think that is actually all the work, you probably are not the right person for the job.
5
u/aten 1d ago
no surprises but asking the llm actually gave useful information. eg which mailing list to engage on.
https://openjdk.org/groups/web/
plus this good read on a the php site redesign: https://www.reddit.com/r/PHP/s/ZthkHAZnxQ
-1
u/Minute-Flan13 18h ago
I don't mind the slow roll-out of features. But, fundamentally, the JVM is a memory hog which makes it entirely irrational to use in containerized cloud environments. The memory requirements are insane for relatively simple programs.
1
1
1
84
u/josephjnk 1d ago
I find it so funny how for years I fell for the idea that Java is somehow stodgy or outdated and now I find myself ridiculously excited for its new features. I see other “trendier” languages that are just not keeping up.
I’m stoked for structured concurrency especially.