5 ms·
Discussions on the mailing list usually tries to avoid the exact syntax for as long as possible to avoid bike-shedding. But according to this mail there would b
by kaba0 4y ago
Discussions on the mailing list usually tries to avoid the exact syntax for as long as possible to avoid bike-shedding. But according to this mail there would be a default nullability (hopefully not-nullable as the default, but it may depend on whether it is a value class or not), and ! and ? as modifiers (and * for type variables).
So `Point p = null` won’t type check, you would have to mark it as `Point?` where Point is a value (primitive) class. There were also points that it should work with the usual type inference, e.g. `final var p = methodThatReturnsNullablePoint()` would be inferred to `Point?`.
- aardvark179 4y agoReference types probably can’t be made non-billable by default as that would break too much. But String! myString = “Definitely not null”; doesn’t look too bad. Edit: it’s worth saying that a lot of careful thought around compatibility goes into features like this. That means the core libraries should be able to transition to non-billable types where this is already a run time requirement, and existing compiled jars must continue to work.
- vips7L 4y agoI don’t think anyone would really use String! everywhere.
- aardvark179 4y agoI think you’ll see it creep into parameter types in the core JDK and it will work its way out from there.
- kaba0 4y agoI think it can work in a binary-additive way — the class file gets a new attribute for nullness information, while missing it (older class files) default to “unspecified”. That can be safely consumed by new code, which will get the updated syntax with a new option (specified on a module/package/class basis) where ‘T’ means ‘T!’ and that should be a proper subset of previously compiling code, so I don’t think anything would break that way. Similarly to how generics and unchecked warnings were rolled out.
- pjmlp 4y agoSee the !! debacle for C#11 to see how changing the default went. So now we are back at warnings if non nullable references are enabled on the compiler settings, and eventually we can turn them into warnings as errors. The biggest issue is the large ecosystem of existing libraries.