This question is more for my curiosity than anything else.
I often employ Java's ternary operator to write shorter code. I have been wondering, however, whether it is possible to use it if one of the if or else conditions are empty. In more details:
int x = some_function();
if (x > 0)
x--;
else
x++;
can be written as x = (x > 0) ? x-1 : x+1;
But is it possible to write if (x > 0) x-1; as a ternary expression with an empty else clause?
x = (x > 0) ? x-- : x++;bex = (x > 0) ? --x : ++x;? Or even better:x = (x > 0) ? x - 1 : x + 1;