News for hackers. Stuff that matters.
Re:OpenJDK mailing list: Null-safety and value types by cogman10 on Tuesday February 07, 2023 @06:04PM (#34701191)
It'll allow the JVM to more aggressively optimize the code (the main benefit).

Annotations are, unfortunately, all over the board. There's a dozen different `NotNull` annotations out there. Having it in the language will make it the last solution to this problem.

You can't do deduction at compile time because you'll end up with different method signatures if someone calls a method with a null vs not. (not to mention the problem with someone calling these methods with reflection)

You can do deduction at runtime (and they likely will), but then you have to deal with the problem of unwinding an optimization when the hypothesis is proven wrong. That can be really costly when the optimization is dealing with memory layout. (Imagine an array of value types where you deduced they should be non-null, yet some unexpected path inserts a null. In that case you have to reallocate the entire array and it's elements in order to handle that).

It's more than just syntactic sugar.

There are no comments on this comment yet.