sGF sGF - 5 months ago 11
Android Question

Not a statetment (Compiler Error Java/Android)

I am trying to do a simple if Statement using the ? pattern. Resulting in an "Not a statement"- Error. Can someone please explain to me why this bullshit is not happening using a normal if statement?

Error:

cursor.isNull(0) ? insert_SQL_RSServer.bindNull(0) : insert_SQL_RSServer.bindLong(0, cursor.getLong(0)); // id


No Error:

if(cursor.isNull(0))
insert_SQL_RSServer.bindNull(0);
else
insert_SQL_RSServer.bindLong(0, cursor.getLong(0));


This is completely the same behavior ....

Answer

The ternary conditional operator is an expression, and it must have a return type, which is determined by the types of the 2nd and 3rd operands.

Therefore, if your bindNull() and bindLong() methods have void return type, they can't be used in this operator.

Comments