If without else ternary operator

前端 未结 10 704
太阳男子
太阳男子 2020-12-05 17:04

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<

相关标签:
10条回答
  • 2020-12-05 17:37

    pstmt != null && pstmt.close;

    The line of code above translates to When the left side of the expression "translates" to true -> execute the right side.

    0 讨论(0)
  • 2020-12-05 17:41

    Just write it out?

    if(pstmt != null) pstmt.close();
    

    It's the exact same length.

    0 讨论(0)
  • 2020-12-05 17:43

    Why using ternary operator when you have only one choice?

    if (pstmt != null) pstmt.close(); 
    

    is enough!

    0 讨论(0)
  • 2020-12-05 17:44

    No, you cannot do that. Instead try this:

    if(bool1 && bool2) voidFunc1();
    
    0 讨论(0)
提交回复
热议问题