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

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -