From JLS - Conditional Operator:
In fact, by the grammar of expression statements (§14.8), it is not permitted for a conditional expression to appear in any context where an invocation of a void method could appear.
Grammar of expression statements from JLS - 14.8:
Certain kinds of expressions may be used as statements by following them with semicolons:
ExpressionStatement:
StatementExpression ;
StatementExpression:
Assignment
PreIncrementExpression
PreDecrementExpression
PostIncrementExpression
PostDecrementExpression
MethodInvocation
ClassInstanceCreationExpression
An expression statement is executed by evaluating the expression; if the expression has a value, the value is discarded. Execution of the expression statement completes normally if and only if evaluation of the expression completes normally.
Unlike C and C++, the Java programming language allows only certain forms of expressions to be used as expression statements.
Now the way you are using the conditional operator is not a valid expression statement, as inferred from it's grammar. And hence you get the compiler error. You have to use it in any of the above mentioned context.