到目前为止,我一直在网络中搜索,语句始终具有if和a ? b : c这样的条件。我想知道是否可以不使用if三元语句而不使用else。假设我有下面的代码,如果PreparedStatement不是null,我希望关闭它
(我正在使用Java编程语言。)
PreparedStatement pstmt;
//....
(pstmt!=null) ? pstmt.close : <do nothing>;发布于 2013-11-18 16:54:48
相反,不,你不能那样做。尝试如下:
if(bool1 && bool2) voidFunc1();发布于 2013-11-18 16:56:45
为什么在只有一种选择的情况下使用三值运算符?
if (pstmt != null) pstmt.close(); 够了!
发布于 2013-11-18 16:54:29
把它写下来?
if(pstmt != null) pstmt.close();完全一样长。
https://stackoverflow.com/questions/20053257
复制相似问题