Boolean checking in the 'if' condition

后端 未结 10 1997
陌清茗
陌清茗 2020-12-03 07:40

Which one is better Java coding style?

boolean status = true;
if (!status) {
    //do sth
} else {
    //do sth
}

or:

10条回答
  •  星月不相逢
    2020-12-03 08:20

    The first one, or if (status) { /*second clause*/ } else { /* first clause */ }

    EDIT

    If the second form is really desired, then if (false == status) , while uglier, is probably safer (wrt typos).

提交回复
热议问题