i was wondering if java have a "default value assignation" (i really don't know how to call it) like what you can do in javascript or python.
For example in js you can do this:
var myVar = variable || "default value";
and if variable contains a value, myVar will have the value of variable otherwise myVar will be the string "default value".
Also in python you can do this:
a = "hello"
b = a or "good bye"
print b #this will print "hello"
a = None
b = a or "good bye"
print b #this will print "good bye"
Can you do this something similar in java? Usually when i have to do this in Java, I do something like this:
String a = b != null ? b : "default value";
But I think what you can do in js or python it's much more readable. Also can you tell me what's the "name" of this ? I know the || symbol it's an or operator, but how it's called when you do this "defaultvalue" thing. Thanks