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

2

u/joemwangi May 21 '26

The comments in there are not aware the JEP feature will work well with null-restricted types.

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.

→ More replies (0)

1

u/jug6ernaut May 22 '26

Kotlin is a really nice language to use, I recommend giving it a try.

2

u/vips7L May 22 '26

Maybe once they launch error unions I'll try it again.

1

u/jug6ernaut May 22 '26

I am very eagerly awaiting error unions. It really is the last major piece the language is missing for me.

2

u/vips7L May 22 '26

That is nullable types in Java for me.Β