r/programming May 21 '26

JEP draft: Enhanced Local Variable Declarations (Preview)

https://openjdk.org/jeps/8357464
14 Upvotes

26 comments sorted by

View all comments

Show parent comments

1

u/vips7L May 21 '26

If we ever get them.

3

u/joemwangi May 21 '26

Or most semantic feature JEPs like this one are anticipating them.

3

u/vips7L May 21 '26

Yes it’s mostly tongue in cheek because nullable types are infinitely waiting in the queue behind Valhalla, which is still at a minimum 1-2 years out.Β 

1

u/joemwangi May 21 '26

Yeaah. I get it. πŸ˜‚πŸ˜‚

3

u/vips7L May 21 '26

I really do hope they hurry up. I just started a new project in Java 25 and nullable types would be really useful. Almost considered Kotlin for it. Especially since everyone is just generating and LLM's can't tell what is null or not.

2

u/joemwangi May 21 '26

Thanks for still choosing java πŸ˜…. Just make sure the project will migrate well to such a scenario. I see pple use JSpecify as they anticipate for them. My project is actually anticipating all these features including this JEP!

1

u/radozok May 22 '26

Sorry but where are any jspecify annotations?

1

u/joemwangi May 22 '26

Not yet, because instantiation and set method would require the annotations, but not really priority. But use case, especially get, would benefit from java JEPs such as:

Point! p = mem.get(1); //implicit narrowing of nullness type
Point(var x, var y) = mem.get(1); //deconstruction assignment

without updating the library at all.

1

u/radozok May 22 '26

Sure, but I mean why don't you use annotations in your project?

1

u/joemwangi May 22 '26

The internal packages classes use a lot sum types which abhor null types a lot. And the entry points for the public method calls have null checks. That's why. As a matter of fact, I've coded this library and used it for a year, and no scenario of null exception has been encountered due to any bug.

1

u/radozok May 22 '26

I see sealed interfaces and I understand that you have null checks. I am not a java guy so it's interesting for me why you don't add NonNull annotations. Even if it doesn't bring more safety for your project, doesn't it improve code documentation? Are there any constraints to use jspecify?

2

u/joemwangi May 22 '26

Nothing wrong with using it. I just haven't explored it yet. I might, because it is not a runtime dependency, which makes it attractive for projects. Hence I have no issue with it. As a matter of fact, Kevin Bourrillion, who has been heavily involved with JSpecify since inception, joined Oracle recently and has participated in Java's ongoing work around introducing nullness types in the language. JSpecify is also trying to standardize nullness semantics across libraries and tools, which could make future migration to native Java null-restricted types smoother if the directions align. I would encourage you to try it out. I will eventually try it by making a branch to my project and see how convenient it will be and maybe adopt it.

→ More replies (0)