不是一个句子(Compiler Error Java/Android)

Spe*_*ius 0 java android compiler-errors

我正在尝试做一个简单的if语句使用?图案.导致"不是声明" - 错误.有人可以向我解释为什么使用正常的if语句不会发生这种情况?

错误:

cursor.isNull(0) ? insert_SQL_RSServer.bindNull(0) : insert_SQL_RSServer.bindLong(0, cursor.getLong(0)); // id
Run Code Online (Sandbox Code Playgroud)

没错误:

if(cursor.isNull(0))
    insert_SQL_RSServer.bindNull(0);
else
    insert_SQL_RSServer.bindLong(0, cursor.getLong(0));
Run Code Online (Sandbox Code Playgroud)

这是完全相同的行为....

Era*_*ran 5

三元条件运算符是一个表达式,它必须有一个返回类型,它由第二个和第三个操作数的类型决定.

因此,如果你bindNull()bindLong()方法有void返回类型,它们不能在此操作中使用.