Implement Null-Coalescing Assignment Operator (??=) for Concise Null Checks

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: None
    • Component/s: core-libs
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Insted of writing three lines of code:

      if ( someRef == null ) {
          someRef = new SomeClass();
      }

      just write one line:

      someRef ??= new SomeClass();

      This improves readability and speeds up coding. The double questionmark can also be used in variable assigment like

      someRef = someMethod() ?? new SomeClass();

      which ensures in one line that someRef does not become null even if someMethod returns null.


            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: