News for hackers. Stuff that matters.
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by gf000 on Friday June 19, 2026 @04:34AM (#48596275)
> The stewardship of Java seems rather lacking

In what way? If anything Java's main developers (employed by Oracle for the most part, working on the completely open source and free OpenJDK) are extremely knowledgeable and are responsible a big jump in how fast the platform evolves. They have added proper algebraic data types to the language, delivered virtual threads and garbage collectors that decouple pause times from heap size. Like if anything, Java is at the best place it has ever been.

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by lmm on Friday June 19, 2026 @04:38AM (#48596306)
> They have added proper algebraic data types to the language

No they haven't. E.g. they added a class that superficially looks like Option but subtly breaks the rules that Option is meant to follow, ensuring that no-one can ever manage to migrate existing codebases away from using `null`.

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by gf000 on Friday June 19, 2026 @04:57AM (#48596424)
Sealed classes/interfaces and records are proper sum and product types.

The stdlib's Option type predates this language update by a long shot, so it doesn't use sealed classes, but it is now possible to have the usual FP "Maybe" type in Java:

``` sealed class Maybe<T> permits Some, None { record Some<T>(T obj) {} record None() {} } ```

(You will probably have to write Maybe.Some and I might have messed up the generic syntax as I wrote it on my phone, but that's mostly how it looks)

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by ahoka on Friday June 19, 2026 @06:38AM (#48597032)
Or just do as Kotlin and embrace null, but in a type aafe way.
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by gf000 on Friday June 19, 2026 @06:45AM (#48597084)
"Funnily", having nullable types be practically `T | Null` gives you union types, not sum types (the latter is, importantly are a disjunct union!)

The main difference is that (T | Null) | Null = T | Null, while Maybe<Maybe<T>> is different from Maybe<T>

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by ahoka on Friday June 19, 2026 @09:02AM (#48598097)
Your point being?
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by tsimionescu on Friday June 19, 2026 @09:30AM (#48598359)
Except this is completely wrong.

First, a record can't extend anything, it's not even valid syntax, so a sealed class can't permit record subclasses. So no, it's not possible to create a Maybe<T> class in Java that can only represent a Some<T> or a None<T> record. You could do it with regular classes, or if it's ok for Maybe<T> to be an interface.

Secondly, regardless of the sealing, nothing in any current or near future of Java prevents you from assigning `null` to any class of any kind you might create. So you can always have `Maybe<T> x = null`, or even `Some<T> x = null`.

None of this will change with the adoption of value classes either. So no, there is absolutely no way in Java to create a real Optional/Maybe type that would guarantee that a variable is either an object of a given type or None. There is probably some way to do it for your specific project using annotation processors, of course, but that is very different from having built-in support.

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by munksbeer on Friday June 19, 2026 @11:50AM (#48599967)
It's probably a typo. He meant sealed interface. I think that should be quite obvious.
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by gf000 on Friday June 19, 2026 @10:37AM (#48599131)
Mistyped, it's sealed interface.

> So you can always have `Maybe<T> x = null`, or even `Some<T> x = null`.

Yeah and? Practically every type system have escape hatches, like Haskell can also do side effects without the IO monad, does it make the latter useless?

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by tsimionescu on Friday June 19, 2026 @10:52AM (#48599307)
The whole point of using Optional/Maybe is to prevent the possibility of accidemtally creating nulls. If you don't make mistakes, then nullability is not a problem. If you do make mistakes, then a class that only helps when you don't make mistakes is basically useless.

This also has significant impact for serialization/de serialization - a classic place where you get unexpected nulls, that Java Optional/Maybe don't help with at all.

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by joe_mwangi on Friday June 19, 2026 @12:10PM (#48600155)
Since they plan to have null-restricted types, then I don't see any issue.
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by Dylan16807 on Friday June 19, 2026 @02:05PM (#48601321)
> plan to

Well wasn't that the argument above, that the stuff they added so far isn't proper at least in part because they didn't fix that problem yet?

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by joe_mwangi on Friday June 19, 2026 @05:05PM (#48603233)
> yet But up the comment section, someone thinks they won't be there 'in the future'
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by Dylan16807 on Saturday June 20, 2026 @05:20AM (#48607706)
The comment that says it won't be there in the near future? That's seems like a reasonable claim to me.

And a promise to eventually fix a busted implementation doesn't undo it being busted for a significant amount of time.

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by joe_mwangi on Friday June 26, 2026 @05:07AM (#48684236)
Better late than never.
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by gf000 on Saturday June 20, 2026 @04:54AM (#48607566)
Disagree.

Types are both for the compiler, as well as for the developer. Maybe types are implicit documentation telling the developer that it is meaningful in the application that this field can have a None state.

That's a huge code smell to ever set null to an Optional/Maybe and code reviews, linters, nullness analyzers all should/will flag such.

Like I have never ever had an NPE from an Optional being null. Sure, complete null safety would be better of course, but in this very instance it ain't buying you much.

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by mrkeen on Saturday June 20, 2026 @02:56PM (#48611888)
This is what your choices are with regard to communicating to the compiler and other developers.

Use a regular class to signal that you may or may not have a value.

Wrap it in an optional to signal that you may or may not have a value.

See the problem?

Re:Project Valhalla, Explained: How a Decade of Work Arrives... by _kidlike on Friday June 19, 2026 @04:52AM (#48596405)
optional is not how algebraic data types are implemented in Java. Basically it's the combination of sealed types and records.
Re:Project Valhalla, Explained: How a Decade of Work Arrives... by joe_mwangi on Friday June 19, 2026 @05:06PM (#48603253)