如果没有其他三元运算符 [英] If without else ternary operator
本文介绍了如果没有其他三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我一直在搜索网络,语句总是有if和else条件,如 a? b:c
。我想知道 if
三元语句是否可以在没有 else
的情况下使用。
假设我有以下代码,我希望关闭 PreparedStatement
如果它不为空
So far from I have been searching through the net, the statement always have if and else condition such as a ? b : c
. I would like to know whether the if
ternary statement can be used without else
.
Assuming i have the following code, i wish to close the PreparedStatement
if it is not null
(我使用的是Java编程语言。)
(I am using Java programming language.)
PreparedStatement pstmt;
//....
(pstmt!=null) ? pstmt.close : <do nothing>;
推荐答案
不,你不能这样做。
而是试试这个:
No, you cannot do that. Instead try this:
if(bool1 && bool2) voidFunc1();
这篇关于如果没有其他三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文