The terminal expression x ? y : z x ? y : z can only be used for conditional assignment. That is, you can do something like:
String mood = inProfit() ? "happy" : "sad";
because the ternary expression returns something (of type String in this example).
It is not intended to be used as a short, built-in if-else . In particular, you cannot use it unless the individual parts return a value or return values ββof incompatible types. (Thus, although you could do this if both methods returned the same value, you should not call it only for side effects).
Thus, the correct way to do this would only be with an if-else block:
if (jXPanel6.isVisible()) { jXPanel6.setVisible(true); } else { jXPanel6.setVisible(false); }
which of course can be reduced to
jXPanel6.setVisible(jXPanel6.isVisible());
Both of these last expressions are more readable to me in that they more clearly indicate what exactly you are trying to do. (And, by the way, you did not accidentally change your conditions? It seems that this is not an operation, not a switch).
Do not mix the number of characters with readability. The key point is what is most easily understood; and gently abuse language features is a definite way to confuse readers, or at least get them to do a mental double take.
Andrzej Doyle Dec 16 2018-10-16 14:52
source share