Re:Project Valhalla, Explained: How a Decade of Work Arrives...
by im3w1l on Saturday June 20, 2026 @01:46AM
(#48606661)
I think you should require the code to be written in such a way that the compiler can verify the value is never read before initialization. There might be some subtleties in how to do that but I don't think it should be insurmountable.
[ Parent
| on HN ]
Re:Project Valhalla, Explained: How a Decade of Work Arrives...
by inigyou on Saturday June 20, 2026 @09:34PM
(#48614837)
It's completely insurmountable. It basically means you can't call any functions during initialization. Including the one that creates the object you want to point your nonnull reference to.
Re:Project Valhalla, Explained: How a Decade of Work Arrives...
by tsimionescu on Monday June 22, 2026 @09:47AM
(#48630095)
...which is exactly how value classes and (after this JEP) records work. You are not allowed to call any instance methods before the call to `super()` (which happens implicitly at the end of the constructor for value classes and for records, unless you explicitly call it), and you are not allowed to call `super()` without first setting a value for all of your fields.