4 ms·
This would be good, but I'd prefer that Java have something like the null operators that C# has. https://docs.microsoft.com/en-us/dotnet/csharp/language-refere
by theandrewbailey 8y ago
This would be good, but I'd prefer that Java have something like the null operators that C# has.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operators https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
- jason0597 8y agoWell, Kotlin has it at least https://kotlinlang.org/docs/reference/null-safety.html https://kotlinlang.org/docs/reference/null-safety.html
- didymospl 8y agoAdding Elvis and safe navigation operators to Java was discussed before Java 7, over 10 years ago. Sadly they never made it even to the official proposal lists and with Optional introduced in Java 8 I don't think we'll get them any time soon. See also Brian Goetz opinion on that subject: https://youtu.be/FdkPHShh628?t=50m17s https://youtu.be/FdkPHShh628?t=50m17s
- deleted 8y ago[deleted]
- Someone1234 8y agoPlus C# is introducing non-nullable reference types (null becomes opt in). https://msdn.microsoft.com/en-us/magazine/mt829270.aspx?f=255&MSPPError=-2147217396 https://msdn.microsoft.com/en-us/magazine/mt829270.aspx?f=25...
- bunderbunder 8y agoIf I read that correctly, what they're actually introducing is a compiler setting (defaulted to off) to have it issue a warning when you assign a null or possibly-null value to a reference that wasn't explicitly annotated to indicate that it expects null. But even with the setting turned on, you're still free to ignore the compiler warnings (assuming you haven't also told it to treat warnings as errors) and blithely assign null to a reference that wasn't flagged as nullable. So it's not quite non-nullability. Which isn't to say that it's a misfeature. It's a huge step in the right direction that will be immensely helpful, and they managed to do it in a way that doesn't break the mountains of C# code that already exist. These sorts of methodical, well-considered design decisions that keep the language moving steadily forward without causing chaos for its users are exactly what's so great about the C# team.