the question is simple, there is a functional equivalent of the famous iif in java?
For example:
IIf (vData = "S", True, False)
Thanks in advance.
the question is simple, there is a functional equivalent of the famous iif in java?
For example:
IIf (vData = "S", True, False)
Thanks in advance.
if is the same as the logical iff.
or
or
EDIT: However its quite likely you don't need a variable instead you can act on the result. e.g.
BTW it may be considered good practice to use
The difference being that is vData is null the first example will throw an exception whereas the second will be false. You should ask yourself which would you prefer to happen.
or in this particular case obviously one could just write
Yeah, the ternary op
? :
The main difference between the Java ternary operator and
IIf
is thatIIf
evaluates both the returned value and the unreturned value, while the ternary operator short-circuits and evaluates only the value returned. If there are side-effects to the evaluation, the two are not equivalent.You can, of course, reimplement
IIf
as a static Java method. In that case, both parameters will be evaluated at call time, just as withIIf
. But there is no builtin Java language feature that equates exactly toIIf
.(Note that the
ifTrue
andifFalse
arguments must be of the same type in Java, either using the ternary operator or using this generic alternative.)