re: Language Features: Best and Worst VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Null-stuff operators like in C# return nullObject?.somefunction() ?? "this is nice sometimes". I actually like Java because of it's ecosystem but ...
 

Is this:

nullObject?.somefunction() ?? "this is nice sometimes"

...a ternary operator? Like

nullObject == null ? somefunction() : "this is nice sometimes"

...in Java?

 

Yeah but you can chain it so it makes things a lot more readable:

foo?.bar?.getResult()?.toString()

a bit late but yeah.. Valentin answerd already but ?. checks for null and prevents null pointer exception and returns null for value but also ?? is null coalescing operator which in case something returns null takes right side value as in java ternary operator but this one's shorter so nullvaluestring ?? "somedefaultvalue" looks a bit prettier :D

code of conduct - report abuse