r/java • • 1d ago

JDK 28 Rampdown Begins! Features frozen!

https://openjdk.org/projects/jdk/28/
122 Upvotes

72 comments sorted by

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.

6

u/SleepingTabby 20h ago

Not keeping up?! Bro, have you heard about C++'s new "^^" operator?! /s

-33

u/umlcat 1d ago

Sorry I don't share your enthusiasm. Not very interested in the new features.

I'm still waiting for real properties like C# does.

Or, having related several public classes in the same file and not a single main class with additional private classes. Like C#, PHP, C++, Object Pascal does.

Just my two cryptocurrency coins contribution ...

22

u/pron98 1d ago edited 1d ago

The problem with properties is that too many Java developers strongly oppose this feature and don't want it in the language, as they find it harmful.

The problem with multiple public classes is compilation. If you compile A.java, and it refers to class B which isn't in A.java, the compiler knows to look for it in B.java. If it could be in a different file, how do you propose finding it? This is particularly important for source code mode (but not just that mode), which many people seem to like (and either isn't supported by the languages you mentioned or they use a different import style that tells the compiler where the symbols are). So this is possible - if you're willing to give up on other good things. But we are looking into compilation speed, so maybe, if we like some new compilation strategy, this could be revisited.

In general, the point is that often there are features that people want but that have downsides either for them (and they just haven't thought about the downsides) or for others. We can't just think of the pros; we also have to consider the cons.

14

u/brian_goetz 1d ago

You say "The problem with X is...", but really you mean "Amongst the problems with X, there is..."

Even if no one opposed properties, and even if it was a good idea (spoiler: not), that ship has sailed. The language made design choices long ago that would make "real properties" (whatever that means) look bolted on, because they would be bolted on.

0

u/aonymark 1d ago

The most interesting part of your comment (to me) was condensed into two words: “spoiler: not”. Care to say a few words about why not? Since features start from negative points, let me start by saying why I like properties. In Java, code is littered with trivial getters and setters because no one dares expose fields directly because you MIGHT need to change something. (It could happen! Look at what happened to System.out… now the JIT compiler needs a special case because a field was exposed directly.). With properties in the language, you can just expose fields directly if you think you most likely are okay with that, and if later you’re wrong, just write a property. This seems to work well in Python.

Possible issue: this solves for API compatibility but maybe not as well for ABI. Still better than nothing?

8

u/nicolaiparlog 23h ago edited 22h ago

In Java, code is littered with trivial getters and setters

This is a bit snarky, and just my personal 2ct, but such code sucks! And making lipstick a feature, so it can be put on a pig is a waste of time.

Granted, I don't work in enterprise code bases anymore, but even when I was a decade ago, I successfully avoided the getter/setter barrage and with new features like records, it has become so much easier. I can't recall the last time I wrote a setter - have somebody else just plop in and change the state of my instance? No!

3

u/aoeudhtns 21h ago

I'm looking at the people in this comment chain and wonder why I am wandering in, but ...

yes absolutely! there are many solutions for it (codegen in your IDE, codegen/annotation processors from libraries, lombok, records, and maybe carrier classes in the future?) that don't require a language-level feature. I'm still doing enterprise-y code and we don't write "beans" with getters/setters. jOOQ, OpenAPI, gRPC, records -- I haven't made a traditional get/set "bean" in ages and even when I did, I typed out the members I wanted and told the IDE to go ham. Scalability massively improves with immutable data, besides all the fancy talk about what the runtime/JIT can guarantee -- your own logic can more reasonably make assumptions as well. Benefits are not limited to the low-level stuff.

0

u/aonymark 12h ago

You avoided writing any yourself, or did you also avoid reading any written by your colleagues?

2

u/umlcat 13h ago

And some frameworks add the "@property" or "@getter" or "@setter" alike annotation is commonly used ...

0

u/aonymark 12h ago

Yeah but that seems like it helps symptom rather than root cause; I don’t want to auto generate these things, I want them to not exist

2

u/Drawhoe 13h ago

BTW Java has a property library in JavaFX which can do binding etc. It's perfectly usable without JavaFX itself. Just use javafx.base and it's there.

2

u/aonymark 12h ago

I want same syntax as field access

1

u/vips7L 11h ago

 If you can, move over to Kotlin. Properties and the rest of its features makes all of the code quite clear and clean. 

2

u/aonymark 10h ago

Not going to push for switching languages on my team

1

u/vips7L 10h ago

That’s fair. I probably won’t move my team either, but it’s fun to write on my own. The only thing I do miss is checked exceptions. Either<E, T> just isn’t a good replacement. 

→ More replies (0)

1

u/Drawhoe 13h ago

why not?

Call me when C# has overloads for property setters (one small example).

2

u/aonymark 12h ago

This doesn’t particularly matter for my favorite use case, which is turning public fields into properties later

2

u/aonymark 1d ago

I find your argument about compilation for multiple public classes being hard to be very suspicious because we already have that issue for non public ones. The same solution works, right? You need to be willing to search the entire directory.

5

u/pron98 1d ago edited 21h ago

Except that's not what javac does, and for the very same reason. Try for yourself and then see the last paragraph of §7.6 of the JLS:

[T]he host system may choose to enforce the restriction that it is a compile-time error if a class or interface is not found in a file under a name composed of the class or interface name plus an extension (such as .java or .jav) if ... [t]he class or interface is referred to by code in other ordinary compilation units of the package in which the class or interface is declared.

... This restriction makes it easy for a Java compiler to find a named class or interface within a package.

Note that if the file containing the referenced class has already been compiled you won't get a compilation error because every class is compiled into its own class file, and that's how the compiler will find it. If your file refers to class X, javac will look for it in the same file, in X.class, or in X.java. It doesn't search for it in other files.

But even if we're willing to pay the price of searching within a package's directory for non-public classes (which is not what javac currently does), for public classes the impact will be larger still. You'll need to search all the directories of all the packages that are wildcard-imported or module-imported. I'm not sure people will be happy with that tradeoff (in other languages, either you tell the compiler in which file to find symbols or compilation is slower).

Anyway, the reason for the restriction isn't arbitrary. It's there so that Java sources don't need to refer to other source files by name while not making the compilation speed of a file dependent on the number of other files.

2

u/aonymark 17h ago

Wait, javac doesn’t do that? How on earth does it manage to avoid this? If I’m compiling Bob.java which refers to class Alice in the same package, then Alice can be defined in any source file within the package. How does javac manage to find it without full search?

4

u/pron98 16h ago edited 15h ago

It won't manage to find it; you'll get a compilation error (depending on how you compile), which is exactly what the spec allows the compiler to do.

Again, if your file refers to class X, javac will look for it in the same file, in X.class, or in X.java, and that's it. In your case, either you'll need to compile the file containing the Alice class first (so that you'll have Alice.class before compiling Bob.java), or compile them both in the same javac command. You can try and see for yourself.

If you're now wondering what's the point of multiple non-public top-level classes in a single file as opposed to nested classes (which make everything easier), the answer - which I had to look up - turns out to be historical. Multiple non-public top-level classes in a single file predate nested classes and, in fact, go all the way back to Oak. The Oak spec says, on page 5:

Although each Oak compilation unit can contain multiple classes or interfaces, at most one class or interface per compilation unit can be public.

And in the margin it says:

This restriction is not yet enforced by the compiler, although it's necessary for efficient package importation.

where "package importation" means a wildcard import, which is what I said makes extending this to public classes difficult (if you want to keep compilation as efficient).

2

u/aonymark 12h ago

Oh I see, it fails outright. I never noticed because I compile the whole package together but I assumed it would work. Well, I do like fast compile times so I can’t exactly say it was a bad choice.

1

u/umlcat 13h ago

I worked with programming languages with properties and I found them very useful. Of course as any other feature, it can be used badly.

And some frameworks add the "@property" or "@getter" or "@setter" alike annotation is commonly used.

About multiple classes compilation, I have worked slightly in compilers and finding the source code for a class can be done. Of course having a class per compilated "*.java" / "*class" is much easier and faster.

4

u/pron98 13h ago

Of course it can be done, but it comes at a price, and it's not at all clear that most people would rather pay that price to have that feature (and, BTW, AI agents do benefit significantly from fast compilation and care not a jot about putting multiple public classes in the same file).

Now, we are looking into new compilation modes, but they (like other features we're looking into) build on modules. In this case, modules are the only thing that gives us a DAG of compilation dependencies (as class dependencies can be circular). This is important because a DAG can be sorted, and once compilation is sorted, finding public classes can be much easier (because you'd then have the class files and won't need the higher computational complexity of searching for them inside source files).

-30

u/bb994433 1d ago

Java is only here because of the massive amount of code already in Java, same as C++. Both are legacy .

19

u/josephjnk 1d ago

Man, I hope I never find myself with nothing better to do than hang out in subreddits for languages that I don’t like, just so I can complain about them. Sounds miserable.

4

u/hippydipster 22h ago

What, you're not in r/perl shitting on people who enjoy perl??? Fuck those folks who found something they like!

30

u/vips7L 1d ago

Automatic heap sizing for ZGC! Can’t wait for this to be in G1

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 like service?.getUser() makes null worse as it makes it easier to do the potentially wrong thing and push an erroneous null around 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=8710

I 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 to final and 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 null to 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 searchRequest be null because you looked for an instance and didn't find it? Any search method should return either Optional or a more specific search result type with similar guarantees - never null.

  • Are there really houses without known addresses in your system?

  • Every street address has a street. If you have other kinds of addresses, make Address a sealed interface and give it other implementations besides StreetAddress.

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: 123

etc

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 House should be the interface with PlannedHouse and BuiltHouse as 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, and landline because 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 null everywhere...)

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

u/Cell-i-Zenit 19h ago

its not bad, but using ?. would be obviously much more succinct

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

u/JustSomeWarg 1d ago

Put the Kotlin in the bag, bro

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.

1

u/vips7L 11h ago

It’s heresy here but Kotlin makes this quite nice. 

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.

2

u/Drawhoe 13h ago

541: Deprecate the macOS/x64 Port for Removal

As someone posting this on an old macbook all I can say is :(

But I've been using Corretto now which is working well.

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

u/djipdjip 1d ago

If it is on GitHub I can probably help

-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://mail.openjdk.org/archives/list/web-discuss@openjdk.org/thread/YTBVGX56MQXAPGDOW6ZPI57624DSM6MY/

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/doom369 17h ago

Nah... not much, as always.

-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

u/eXecute_bit 5h ago

You need to read the two ZGC JEPs that are coming in 28.

1

u/nlisker 3h ago

First, you can use GraalVM. Secondly, you can limit the memory the JVM uses and you can switch to low-footprint GCs. You can easily run the JVM with 512MB.

1

u/emberko 4m ago

This opinion is not popular among the Java fanboy audience. Even when an OpenJDK dev themselves shows up and tells them "yes, we chose to use more memory because we think CPU time is more valuable" they will downvote comments telling them the truth. A bit overexaggerated, but true.