java - Comparing Boolean Value -
i have checkbox named testcheck. when user check value becomes true. able implement compare of true/false following ways
1.
if (testcheck.getvalue() == boolean.true) { // respective code }
2.
if (testcheck.getvalue().equals(boolean.true)) { //respective code }
3.
if (testcheck.getvalue()) { //respective code }
my questions:
- is there difference ?
- if yes, 1 best way of implementation ?
it depends....
if return type of testcheck.getvalue()
boolean
, 3rd 1 ok.
but if boolean
(big b), do:
boolean.true.equals(testcheck.getvalue())
to avoid npe during autoboxing.
Comments
Post a Comment