I was wondering if it was possible to do a ternary operation but without returning anything.
If it’s not possible in Java is it possible in other languages, if so which ones apply?
name.isChecked() ? name.setChecked(true):name.setChecked(false);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, you can’t. But what’s the point of this over an
if-elsestatement? Are you really trying to save 7 characters?or if you prefer bad style:
Never mind the fact that you can just do (in this case):
The point of the ternary or “conditional” operator is to introduce conditionals into an expression. In other words, this:
is meant to be shorthand for this:
If there is no value being produced, the conditional operator is not a shortcut.