/**************************************************************************
 *                     android 三目运算符 运用错误
 * 说明:
 *     今天想把一个if else语句直接用三目运算来做,结果总是出错,调试了一段
 *  时间,找了点资料,找到了原因。
 *
 *                                        2016-4-13 深圳 南山平山村 曾剑锋
 *************************************************************************/


1、参考文档:
    java ?: 三目运算符
        http://blog.csdn.net/shuilan0066/article/details/6174031

2if else 表达式:
    if (GPIOFuncCtrl.getGPIOState(GPIOFuncCtrl.DETECT) == 0) 
        shutdownState.setBackgroundColor(Color.GREEN);
    else 
        shutdownState.setBackgroundColor(Color.RED);

3、三目运算表达式:
    GPIOFuncCtrl.getGPIOState(GPIOFuncCtrl.DETECT) == 0 ? shutdownState.setBackgroundColor(Color.GREEN) : shutdownState.setBackgroundColor(Color.RED);

4、三目运算出错现象:
    Syntax error on token "==", invalid AssignmentOperator

5、出错原因:
    三目运算符进行运算后返回的是一个值必须用变量进行保存或直接打印或return返回结果值。

 

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2021-11-19
  • 2021-12-17
猜你喜欢
  • 2021-11-16
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案