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.
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.
- duplicates
-
JDK-8289289 Add the `null`‑coalescing operator (`a ?? b`)
-
- Closed
-