[Solved] How to use the ternary operator in Java without an else branch

[ad_1]

As the JLS states:

It is a compile-time error for either the second or the third operand
expression to be an invocation of a void method.

Assuming that your setter is more likely to have no return type, then no it’s not possible to use the ternary operator in this context.

[ad_2]

solved How to use the ternary operator in Java without an else branch