Null Coalescing Operator

Recently, Adam showed us an interesting bit of syntax for C#:

a = b ?? c;

which is equivalent to:

if(b != null){
a = b;
}else{
a = c;
}

I was reminded of it again today when I learned it is called the “Null Coalescing Operator”. Javascript has something similar with:

a = b || c;

I’ve used the hell out of it in javascript so it was cool to see it available elsewhere. Will it come to java?

Comments are closed.