JAVA - what is the difference between void and boolean methods? -
i new java. writing wrapper-library in java make functions available in basic-like language.
i got stock @ point when noted code not executed in java-library although compiler did not complain (using eclipse). resolved replacing code follows:
public void videoquality(int vquality) //did not work
into
public boolean videoquality(int vquality) //works
here complete code-snippets:
public void videoquality(int vquality) //did not work {if (vquality==16) { vidquality=16; } else if (vquality==-16) { vidquality=-16; } else if (vquality==0) { vidquality=0; } else vidquality=-16; vitamioext.setvideoquality(vidquality); } public boolean videoquality(int vquality) //works {if (vquality==16) { vidquality=16; } else if (vquality==-16) { vidquality=-16; } else if (vquality==0) { vidquality=0; } else vidquality=-16; vitamioext.setvideoquality(vidquality); return true; }
i think void corresponds sub in visual basic while boolean corresponds function.
i found odd following code worked using void
public void setvolume(float leftvolume,float rightvolume) { vitamioext.setvolume(leftvolume, rightvolume); }
i surely missing obvious can't see why void-code not work while boolean-code worked.
maybe depends how call code?
anyone can shed lights?
edit: clarify not working, meant code:
vitamioext.setvideoquality(vidquality);
did not execute in void-snippet.
edit2: vidquality declared in different part of code. posted snippets since problems , variables functioning.
edit3: @ end, guess must have called void-snippet erroneously although compiler did not compile. in either case, both snippets should execute although of course void-snippet right 1 use since did not expect return-value.
the difference between
public void videoquality(int vquality)
and
public boolean videoquality(int vquality)
is former doesn't return value, , latter (specifically, boolean
value). that's full extent of difference.
that means, instance, void
version of videoquality
:
boolean x = videoquality(10); // not compile videoquality(10); // compile
...because can't assign result of void
function variable.
if used boolean
version of videoquality
:
boolean x = videoquality(10); // compile videoquality(10); // compile
...because although can assign result of function returns boolean
boolean
variable, don't have to. can ignore return value if like. (usually that's not practice, it's okay.)
i think void corresponds sub in visual basic while boolean corresponds function.
loosely speaking, yes. void
indicates function has no return value, sub
in vb. else (boolean
, int
, foo
, whatever) indicates a) function has return value, , b) of given type. that's function
in vb.
Comments
Post a Comment