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


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.

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