-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New null operator =?? #1632
Comments
The intuition would be "compute a value; if it is non-null then store it, otherwise do nothing". This is a quite meaningful action, so it would be nice if we could express it without repeating the variable name (and without having that no-op assignment).
We should note the connection to other proposals about going ahead / skipping expression evaluation in cases where a given value is null. For instance, |
I believe this is a duplicate of #288. A collection of more null-aware syntax by @lrhn is here. I can understand updating old variables, but how would this work with declaring new ones? int one = getNonNull();
one =?? nullable(); // skipped
int two =?? nullable(); // what happens here?
int? three =?? nullable(); // or here? |
The syntax doesn't need to work for declarations. You can't write |
If we had a pipe operator, say Or if we had unary function shorthands, We should totally have a pipe operator! |
(But this is a duplicate of #288, so closing in favor of that). |
This tracker is for a null safety language suggestion.
Just as today we have ??= to make an assignment if the left operand is null, it would be highly useful to have a corollary operator.
=?? would not make an assignment if the right operand is null
theVariable =?? someNullValue;
... would be less verbose with clearer intention than...
theVariable = someNullValue ?? theVariable;
The text was updated successfully, but these errors were encountered: