如果没有 else 三元运算符 [英] If without else ternary operator

查看:65
本文介绍了如果没有 else 三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在网上搜索,语句总是有 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>;

推荐答案

不,你不能那样做.而是试试这个:

if(bool1 && bool2) voidFunc1();

这篇关于如果没有 else 三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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