[HN Gopher] OpenJDK mailing list: Null-safety and value types
___________________________________________________________________
OpenJDK mailing list: Null-safety and value types
Author : kaba0
Score : 16 points
Date : 2023-02-07 21:54 UTC (1 hours ago)
(HTM) web link (mail.openjdk.org)
(TXT) w3m dump (mail.openjdk.org)
| topspin wrote:
| I don't care how they get there, as long as they get there. In
| this case they're realizing that NULL makes optimization
| difficult and are swerving into solving this 27 year old instance
| of the "billion-dollar mistake." NPEs shouldn't exist in work-a-
| day code.
| sam_lowry_ wrote:
| What syntactic sugar they offer is not clear from the mail.
|
| There are already lots of techniques, from annotations to
| Optional.ofNullable but none matches the simplicity of != null.
|
| They can also go the route of `effectively final` and make the
| compiler deduce nullness instead of marking it explicitly.
| yarg wrote:
| There's not really a nice way of implementing the syntax
| without changing the language.
|
| Although perhaps they could resolve this with magic imports?
| import java.lang.magic.optional; public class
| Foo{ public static void main(String...args){
| Foo? f = ...; if(f){
| f.doThings(); } f.doThings();
| //compile time error } }
|
| The idea being that importing the magic class enables the
| cleaner syntax.
| yarg wrote:
| I've alway felt "billion dollar mistake" is unreasonably
| hyperbolic.
|
| In retrospect it would be very nice to have a language level
| ability to define something as optional, and require existence
| checking for such values;
|
| But it wasn't so obvious at the time.
| highwind wrote:
| I believe ML family of languages do not have null. And it was
| developed well before Java. So I don't think timing was the
| issue.
| revskill wrote:
| It's in correct direction to make nullness more explicit through
| the type system.
| mabbo wrote:
| If I'm understanding this correctly, is the author saying that a
| future version of Java may let me use `String! foo` and the
| compiler will make sure this variable cannot be null?
|
| That would be very helpful indeed.
___________________________________________________________________
(page generated 2023-02-07 23:00 UTC)