问题分配的左侧必须是变量 [英] Issue with The left-hand side of an assignment must be a variable

查看:92
本文介绍了问题分配的左侧必须是变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试转换此

if ( prop.getDateSaisie() == null ) prop.setDateSaisie(new Date()) ;
else                                prop.setDateSaisieModif(new Date()) ;

像这样的Java三元运算符

To the Java ternary operator like this

prop.getDateSaisie() == null ? prop.setDateSaisie(new Date()) : prop.setDateSaisieModif(new Date()) ;

我得到作业的左侧必须是变量

所以我必须这样做如果 else 或者我错过了什么?

So i have to do it whith if else or i miss something ?

推荐答案

您可以阅读编译器错误:左侧必须是变量

三元或条件运算符的要点是将条件引入表达式

You can read the compiler error: left hand side must be a variable.
The point of the ternary or "conditional" operator is to introduce conditionals into an expression.

这意味着您必须以这种方式编写三元运算符:

Meaning you have to write the ternary operator in this fashion:

variable = condition ? true : false;

这篇关于问题分配的左侧必须是变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆