3 ms·
Could the add some non-nullable annotation like apple did when updating objective-c to play nicely with Swift's optionals?
by yoz-y 9y ago
Could the add some non-nullable annotation like apple did when updating objective-c to play nicely with Swift's optionals?
- dep_b 9y agoNon-nullable is a promise not a guarantee. It does absolutely nothing in terms of useful warnings or compiler errors within Objective-C, it only explains how Swift should consume the Objective-C API. It's still entirely possible to get a nil from Objective-C while the API is declared as nonnullable, this even happened to me with Apple's own API's if abused to a certain limit.
- yoz-y 9y agoYes but if Java 10 (for example) introduced this annotation then the JVM10 could transform a null returned from a non-nullable annotated function to an exception. Compile time static checks could also be added to guarantee that such a method does not return null. But you could still use such a function from a previous java version albeit you would sacrifice the checks. It is a way to introduce the benefits (as long as the library is developed properly) of non-nullable types without sacrificing retro compatibility. Edit: I remember a bug in earlier version of Swift Cocoa binding where getting calendar events without titles would hang without possibility of recourse because of this problems.
- DougBTX 9y agoSomething like what they are trying for C# may work for Java too: https://blogs.msdn.microsoft.com/dotnet/2017/11/15/nullable-reference-types-in-csharp/ https://blogs.msdn.microsoft.com/dotnet/2017/11/15/nullable-...