convert from boolean to byte in java -


i need set byte value method parameter. have boolean variable isgenerated, determines logic executed within method. can pass directly boolean byte parameter not allowed , can't cast in java. solution have looks this:

myobj.setisvisible(isgenerated ? (byte)1 : (byte)0); 

but seems odd me. maybe better solution exists this?

your solution correct.

if may avoid 1 cast doing following way:

myobj.setisvisible((byte) (isgenerated ? 1 : 0 )); 

additionally should consider 1 of following changes implementation:

  • change method setvisiblitystate(byte state) if need consider more 2 possible states

  • change method setisvisible(boolean value) if method it's looking like


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -